NSDecimalNumber zeros following decimal point (iPhone SDK)

前端 未结 2 1199
醉话见心
醉话见心 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

    0 讨论(0)
  • 2021-02-10 00:19

    Why not use textFieldThree.text=[NSString stringWithFormat:@"%.2f",[fieldOneDN floatvalue]];

    (or something similar - sorry I'm on a PC right now so can't test this)

    0 讨论(0)
提交回复
热议问题