How to trim zeros after decimal point

后端 未结 8 1683
栀梦
栀梦 2021-01-05 05:38

I am trying to trim zeros after a decimal point as below but it\'s not giving desired result.

trig = [currentVal doubleValue];
trig = trig/100;
NSNumberForma         


        
8条回答
  •  不思量自难忘°
    2021-01-05 06:06

    From the documentation, it looks like setFractionDigits: is only for converting the other way.

    The best thing to do is probably to convert your number to an integer before formatting it e.g.

     double converted = round(trig); // man round for docs
    

    You can use also the formatting functions of stringWithFormat: of NSString, but then you will lose all the localisation advantages you get with NSNumberFormatter.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题