1

I have been trying to find a solution to the below problem:

I'm dealing with Kuwaiti currency in which the lowest amount is 5 fils (coins) and the highest amount is 20 Kuwaiti Dinars (bill notes).

The number format is X.XXX (KD.fils) in which the largest number of decimal digits after the "dot" is 3.

The KD can be any number from 0 to infinity, however, the fils exist only in 5 increments: eg. 000 fils, 005 fils, 010 fils, 015 fils, 985 fils, 990 fils, all the way up to 1000 (1.000 KD).

Given the following:

1) 12.583 ---- 12.585

2) 12.582 ---- 12.580

3) 100.247 ---- 100.250

4) 100.999 ---- 101.000

5) 1009.998 ---- 1010.000

6) 1009.992 ---- 1009.990

How do I round the last three decimal numbers to the nearest 5 and, if the number exists as it does in example no. 4 and 5, it should round it to the next whole KD ie from 100 KD to 101 KD in the case of example 4 (the condition is when fils exceeds 995)

How can I achieve the above?

Falcon
  • 11
  • 3
  • 1
    Multiply by 1000, round to nearest 5, divide by 1000. For the second step, you'll easily find the answer on this site with a simple search. – Blackhole May 20 '20 at 20:12
  • 2
    Are you using floating point numbers for currency? If so, please see this stack overflow question on why you shouldn't. https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency – Jack Cole May 20 '20 at 20:22

0 Answers0