0

I wanted to know what is the best way to read and store currency values in C such as 11.22.

I tried scan("%f", &num), but I get random values at the end of the float.

Is there any way to read only up to the second decimal place?

If I add these numbers, they are not accurate; as it rounds down for some reason. Adding 11.22 + 22.33 is better than 11.220000 + 22.330000, as I get random values at the end; I don't know why!

Is there a way to return an error to the user if it goes beyond the 2nd decimal place and if the user enters a character.

I was thinking converting a (array)string into a floating point.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
JessicaRam
  • 21
  • 3

0 Answers0