I know how to do X amount of leading zeros, and I know how to do X amount of decimal points. But, how do I do them both?
I am looking to have 4 leading zeros to a decimal precision of 2: 0000.00. Therefore 43.4 would be 0043.40
You can do zero padding before the Decimal point. fprintf(stdout, " PRINT - INTEGER : %05d and FLOAT : %014.8f n", num_int, num_flt); It will show total 14 digits and 8 digits after decimal point.
Step 1: Get the Number N and number of leading zeros P. Step 2: Convert the number to string using the ToString() method and to pad the string use the formatted string argument “0000” for P= 4. val = N. ToString("0000");
You can do it like this: printf("%. 6f", myFloat); 6 represents the number of digits after the decimal separator.
Try this printf
(C, Perl, PHP) format string:
"%07.2f"
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