How do I format a Float to String:
1 => "1.0"
1.12345 => "1.12345"
Instead of:
String.Format("{0:0.0}", 123.0); // Limit amount of digits
Thank you!
Is there a maximum limit to the number of digits?
You can instead use:
String.Format("{0:0.0#####}", floatVal)
You can extend the #
out to whatever you want/consider reasonable. Following the .
of the format specifier, a 0
indicates the decimal precision place should always be shown, while #
indicates it should be shown if present.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With