This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
- C
- C++
- C#
- D
- Dart
- Elixir
- Fortran
- Go
- Haskell
- JS
- JS
- 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.
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);
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.