Decimal mark printing

How do I get 1.371429how 01.37. Isn't it %2.02f? I need to have a leading zero, and also round it to two decimal places.

+4
source share
1 answer

Try the following:

#include<stdio.h>

int main()
{
    double a = 1.2345666;
    printf("%05.2lf\n", a);
    return 0;
}

Here 05 says: "print 5 columns with leading zeros." .2 says "print decimal digits up to two columns." 2 decimal digits + 1 . + 2 integer part => only 5 columns that you must print.

+1
source

Source: https://habr.com/ru/post/1608460/


All Articles