0

Why the scanf is not storing correct value in variable salary?

Input given is 45689.4527 but output is 45689.453125… https://code.sololearn.com/c8sPyiw1eJnU/?ref=app

14th Apr 2021, 1:19 PM
Krishna Kumar
Krishna Kumar - avatar
4 Respuestas
+ 2
Krishna, I'm just guessing because `double` is capable of handling better precision over `float`. But it was a guess, someone more knowledgeable can answer that doubt in more technical way 👍
14th Apr 2021, 2:18 PM
Ipang
+ 1
Try to use `double` instead, I got correct output using `double`.
14th Apr 2021, 1:31 PM
Ipang
+ 1
Ipang you're right double gives the correct answer but why the float gives incorrect value ?
14th Apr 2021, 2:15 PM
Krishna Kumar
Krishna Kumar - avatar
+ 1
Okay
14th Apr 2021, 2:19 PM
Krishna Kumar
Krishna Kumar - avatar