Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing a double without the decimal places

Tags:

c

I have a number stored as a double and want to print it without the decimal places. So if I had the double value 919545634521.000000, it is always printed with the decimal places added to it. How can I print it without it so it looks like: 919545634521?

#include<stdlib.h>

int main()
{
    double number = 9220343120;
    printf("%??\n", number);
}
like image 555
phoenix Avatar asked Jul 26 '11 07:07

phoenix


1 Answers

try

printf("%.0lf\n",phoneNum);

you may also prefer

long long phoneNum;
phoneNum = strtoll(buffer,NULL,0);
printf("%lld\n",phoneNum);

instead. Depending on the system, though, you may need other function to convert (I think it's _strtoui64 for windows).

like image 58
Michael Krelin - hacker Avatar answered Oct 26 '22 17:10

Michael Krelin - hacker