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.
std::array<char, 23> buffer;
std::string s{};
if (auto [ptr, ec] = std::to_chars(buffer.data(), buffer.data() + buffer.size(), x, std::chars_format::fixed, 2); ec == std::errc{}) {
s = std::string(buffer.data(), ptr);
} else {
s = std::make_error_code(ec).message();
}
string s = $"{x:F2}";
var s = x.toStringAsFixed(2);
s = Float.to_string(x, decimals: 2)
S = io_lib:format("~.2f", [X]).
write (unit=s,fmt="(F20.2)") x
s <- showFFloat (Just 2) x ""
num.toFixed(2)
String s = String.format("%.2f", x);
String s = "%.2f".formatted(x);
s = "%.2f".format(x)
s = string.format("%.2f",x)
$s = sprintf('%.2f', $x);
$s = sprintf "%.2f", $x;
s = f'{x:.2f}'
s = '{:.2f}'.format(x)
s = '%.2f' % x
s = format(x, '.2f')
s = "%.2f" % x
let s = format!("{:.2}", x);