How do I find the next multiple of 10 of any integer?

后端 未结 12 1104
Happy的楠姐
Happy的楠姐 2020-12-08 04:15

Dynamic integer will be any number from 0 to 150.

i.e. - number returns 41, need to return 50. If number is 10 need to return 10. Number is 1 need to return 10.

12条回答
  •  再見小時候
    2020-12-08 04:48

    How about using integer math:

    N=41
    N+=9   // Add 9 first to ensure rounding.
    N/=10  // Drops the ones place
    N*=10  // Puts the ones place back with a zero
    

提交回复
热议问题