1

I can't figure out how to do something very simple in my program.

Given a float value f (it could be 0, or it could be 5 million, etc), I need to find the first value x such x >= f (x is greater than f) and x is a multiple of 5.

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
CodeGuy
  • 28,427
  • 76
  • 200
  • 317

2 Answers2

1

Divide by 5, round up to the next integer (using ceil() or similar), multiply by 5 again.

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
0

You can use modulo operator and do something like:

x = f - f % 5 + 5