Alex Rivera | Logout

Truncating double without rounding in C

Asked 2010-03-31T20:30:17.207
10

Lets consider we have a double R = 99.999999; (which may be obtained by a result of some other computation),now the desired output is 99.99

I tried using printf("%.2lf",R); but it's rounding off the value.How to get the desired output ? (preferably using printf)

c++ c
Edit
Report

1 Answer

2

sprintf it into a buffer, and then put the NUL char two bytes past the '.'

Then printf your final string using the intermediate one.

answered 2010-03-31T20:32:27.327

Your Answer