How to convert NSDecimal to NSString with custom format

How to show NSDecimal with custom format? Something like "% .2f" or "% .4f". NSDecimalString just throws zeros (e.g. 4.10 becomes 4.1).

+4
source share
1 answer
[NSString stringWithFormat:@"%.2f", [[NSDecimalNumber decimalNumberWithDecimal:myDecimal] doubleValue]] 

Alternatively, consider NSNumberFormatter .

+4
source

Source: https://habr.com/ru/post/1344275/


All Articles