Round currency closest to five

后端 未结 4 894
庸人自扰
庸人自扰 2021-01-19 05:19

I\'d like to round my values to the closest of 5 cent for example:

5.31 -> 5.30
5.35 -> 5.35
5.33 -> 5.35
5.38 -> 5.40

Currentl

4条回答
  •  无人共我
    2021-01-19 05:44

    Turns out..it's really simple

    let x: Float = 1.03 //or whatever value, you can also use the Double type
    let y = round(x * 20) / 20
    

提交回复
热议问题