Logo

Programming-Idioms

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

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another C# implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "fmt"
s := fmt.Sprintf("%.1f%%", 100.0*x)
import java.text.DecimalFormat;
String s = new DecimalFormat("0.0%").format(x);
my $s = sprintf '%.1f%%', $x * 100;
let s = format!("{:.1}%", 100.0 * x);
#include <stdio.h>
printf("%.1lf%%\n", x * 100);
import std.string : format;
string percent = format("%.1f%%", x * 100.0);
SysUtils
s :=format('%.1f%%', [100.0*x]);  
var s = "${(x * 100).toStringAsFixed(1)}%";
s = "%.1f%%" % (100 * x)
s = Numeric.showFFloat (Just 1) (100*x) "%"
s = '{:.1%}'.format(x)
$s = number_format($x * 100.0, 1) . '%';
s = "#{Float.round(x * 100, 1)}%"
s = string.format("%.1f%%", x*100)
const s = Math.round (x * 1000) / 10 + '%'
write (*,'(F5.1,"%")') x*100.
s = f"{x:.01%}"
const percentFormatter = new Intl.NumberFormat('en-US', {
  style: 'percent',
  maximumSignificantDigits: 3
});

const s = percentFormatter.format(x);
String s = String.format("%.1f%%", x * 100f);