NSDecimalNumber zeros following decimal point (iPhone SDK)

前端 未结 2 1201
醉话见心
醉话见心 2021-02-09 23:35

I have the following code

(...)
numberStyle = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:NSRoundPlain
                                                  


        
2条回答
  •  独厮守ぢ
    2021-02-10 00:08

    NSDecimalNumber subclasses NSNumber so you just need to use NSNumberFormatter

    
     NSDecimalNumber * dn = [NSDecimalNumber decimalNumberWithString:@"1234.5"];
     NSNumberFormatter * nf = [[NSNumberFormatter alloc] init];
     [nf setMinimumFractionDigits:2];
     [nf setMaximumFractionDigits:2];
     NSString *ns  = [nf stringFromNumber:dn];
    

    Simples

提交回复
热议问题