by Dinesh Thakur Category: C Programming (Pratical)

#include <stdio.h>

int main()
        {
        double a=3.151, b=3.249;
        double x=3.15, y=3.25;
        printf("3.151 printed with 1d becomes => %.1f\n",a);
        printf("3.249 printed with 1d becomes => %.1f\n",b);
        /* Rounds when not exactly half way: 3.151=>3.2 and 3.249=>3.2 */
        printf("3.15 printed with 1d becomes => %.1f\n",x);
        printf("3.25 printed with 1d becomes => %.1f\n",y);
                /* Truncates when exactly half way: 3.15=>3.1 and 3.25=>3.2 */
        return 0;
        }
 Program to See if Printf() Rounds or Truncates


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.