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.
- JS
- JS
- C
- C++
- C#
- D
- Dart
- Elixir
- Fortran
- Go
- Haskell
- Java
- Java
- Java
- Java
- Lua
- Lua
- PHP
- Pascal
- Perl
- Python
- Python
- Python
- Python
- Ruby
- Rust
const percentFormatter = new Intl.NumberFormat('en-US', {
style: 'percent',
maximumSignificantDigits: 3
});
const s = percentFormatter.format(x);
Uses an Intl.NumberFormat to create a human-readable percentage string.
const s = Math.round (x * 1000) / 10 + '%'
Sadly there's no builtin in JavaScript for this sort of thing.
string s = $"{x:p1}";
var s = "${(x * 100).toStringAsFixed(1)}%";
s = "#{Float.round(x * 100, 1)}%"
write (*,'(F5.1,"%")') x*100.
s = Numeric.showFFloat (Just 1) (100*x) "%"
String s = "%.1f%%".formatted(x * 100);
import static java.math.RoundingMode.HALF_UP;
import static java.text.NumberFormat.getPercentInstance;
import java.text.NumberFormat;
NumberFormat f = getPercentInstance();
f.setMaximumFractionDigits(1);
f.setRoundingMode(HALF_UP);
String s = f.format(x);
local s = (x-x%10^-3)*100 .."%"
$s = number_format($x * 100.0, 1) . '%';
my $s = sprintf '%.1f%%', $x * 100;
sprintf uses % as an escape character for its formatting codes, therefore use %% to generate a literal %.
s = '{:.1%}'.format(x)
.1 means only one digit after decimal point.
% handles the "multiplication" and shows the percentage sign.
% handles the "multiplication" and shows the percentage sign.
s = '%.1f%%' % (x * 100)
s = format(x, '.1%')
s = f"{x:.01%}"