0

Suppose in the below code I give a float value of 5.6 ,when executed gives 5.59999999968 ,I mean It give a value very nearto 5.6

https://code.sololearn.com/c98KDr30Ax0H/?ref=app Suppose I just want up-to 3 decimals, that too using double, how can I get it,like what we use %.3f In c, is there any method like that? Every answer is appreciated :)😁

8th Sep 2020, 2:17 PM
RuntimeERROR
RuntimeERROR - avatar
3 Respuestas
+ 2
Doubles and floats are not precise. It is because of the way values are stored in binary numeral system. If precision is an issue, consider using BigDecimal class. It is precise because it stores values and scales as integers.
8th Sep 2020, 2:35 PM
Aleksandrs
Aleksandrs - avatar
+ 1
Acha, tq ~ swim ~
8th Sep 2020, 2:27 PM
RuntimeERROR
RuntimeERROR - avatar