-4

How can i can calaulate this in c? :

float x = 5;
float y = 4.999

float z = x-y; // 0.001000

Now i want z to be exactly 3 digits after the point, so that z will be = 0.001.
I don't need to print z, i just need to initialize it with 0.001.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
user2637293
  • 333
  • 1
  • 5
  • 17

1 Answers1

0

Use the integer datatype and transform all numbers to a multiply of 1000

int x = 5000
int y = 4999

int z = x-y // 1
code monkey
  • 2,094
  • 3
  • 23
  • 26