I have some double values I want to convert to a string with this pattern:
0.xx or x.xx
Currently I have try this:
double.ToString("#.#0");
What should I add in order to see zero in case my number start with zero?
Double-precision floating-point format (sometimes called FP64 or float64) is a computer number format, usually occupying 64 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point.
printf("%. 2f", value); The %. 2f syntax tells Java to return your variable (value) with 2 decimal places (.
The %s operator is put where the string is to be specified. The number of values you want to append to a string should be equivalent to the number specified in parentheses after the % operator at the end of the string value. The following Python code illustrates the way of performing string formatting.
just use
myDouble.ToString("0.00")
that should do the trick
myDouble.ToString("N2")
should also work.
Have a look at
MSDN: Custom Numeric Format Strings
MSDN: Standard Numeric Format Strings
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