This language bar is your friend. Select your favorite languages!

Idiom #65 Format decimal number

From real value x in [0,1], create its percentage string representation s with one digit after decimal point. E.g. 0.15625 -> "15.6%"

s = '{:.1%}'.format(x)
#include <stdio.h>
printf("%.1lf%%\n",x);
import std.string : format;
string percent = format("%.1f%%", x * 100.0);
var s = "${(x * 100).toStringAsFixed(1)}%";
s = "#{Float.round(x * 100, 1)}%"
import "fmt"
s := fmt.Sprintf("%.1f%%", 100.0*x)
s = Numeric.showFFloat (Just 1) (100*x) "%"
import java.text.DecimalFormat;
String s = new DecimalFormat("0.0%").format(x);
s = string.format("%.1f%%", x*100)
$s = number_format($x * 100.0, 1) . '%';
SysUtils
s :=format('%.1f%%', [100.0*x]);  
$s = sprintf "%.1f", $x*100;
s = "%.1f%" % 100.0 * x
let s = format!("{:.1}%", 100.0 * x);

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org