开发者

How to convert NSDecimal to NSString with custom format

开发者 https://www.devze.com 2023-02-18 19:05 出处:网络
How can开发者_运维技巧 I show NSDecimal with custom format? Something like \"%.2f\" or \"%.4f\". NSDecimalString just throws away zeroes (e.g 4.10 becomes 4.1).[NSString stringWithFormat:@\"%.2f\", [[

How can开发者_运维技巧 I show NSDecimal with custom format? Something like "%.2f" or "%.4f". NSDecimalString just throws away zeroes (e.g 4.10 becomes 4.1).


[NSString stringWithFormat:@"%.2f", [[NSDecimalNumber decimalNumberWithDecimal:myDecimal] doubleValue]]

Alternatively, look into NSNumberFormatter.

0

精彩评论

暂无评论...
验证码 换一张
取 消