Objective c Xcode小数位

Objective c Xcode小数位,objective-c,xcode,decimal,max,Objective C,Xcode,Decimal,Max,我想将数字值显示为最大小数位数。如果未将浮点格式设置为: @"%.1f" 然后它将显示数字,例如1.000000。我想要的是这个数字应该有它所需要的最大小数位数 我不需要 1.5需要小数点后1位 1.24需要两位小数 是否有某种代码将数字格式化为最大小数位数?将“f”替换为“g” 从printf(3): gG The double argument is converted in style f or e (or F or E for G conver- sion

我想将数字值显示为最大小数位数。如果未将浮点格式设置为:

@"%.1f"
然后它将显示数字,例如1.000000。我想要的是这个数字应该有它所需要的最大小数位数

我不需要

1.5需要小数点后1位

1.24需要两位小数

是否有某种代码将数字格式化为最大小数位数?

将“f”替换为“g”

printf(3)

 gG      The double argument is converted in style f or e (or F or E for G conver-
         sions).  The precision specifies the number of significant digits.  If the
         precision is missing, 6 digits are given; if the precision is zero, it is
         treated as 1.  Style e is used if the exponent from its conversion is less
         than -4 or greater than or equal to the precision.  Trailing zeros are removed
         from the fractional part of the result; a decimal point appears only if it is
         followed by at least one digit.