Is it possible to display a float variable only out to the 2nd decimal place (hundredths place)?
Jeremy1026 macrumors 68020 Original poster Nov 3, 2007 2,215 1,029 Sep 3, 2008 #1 Is it possible to display a float variable only out to the 2nd decimal place (hundredths place)?
robbieduncan Moderator emeritus Jul 24, 2002 25,611 893 Harrogate Sep 3, 2008 #2 Look at the documentation for NSString stringWithFormat. You can specify the number of decimal places easily.
Look at the documentation for NSString stringWithFormat. You can specify the number of decimal places easily.
Jeremy1026 macrumors 68020 Original poster Nov 3, 2007 2,215 1,029 Sep 3, 2008 #3 Thanks for your help. Incase anyone else finds this in a search, the way to do it is to use %.2f in the stringWithFormat: method.
Thanks for your help. Incase anyone else finds this in a search, the way to do it is to use %.2f in the stringWithFormat: method.
R Ron C macrumors member Jul 18, 2008 61 0 Chicago-area Sep 3, 2008 #4 Yup - that's a winner... (more fodder for searches) The String Programming Guide for Cocoa section on String Format Specifiers describes all of the options, but for things like the ".2" part you need to see the referenced IEEE printf() description. Ron C.
Yup - that's a winner... (more fodder for searches) The String Programming Guide for Cocoa section on String Format Specifiers describes all of the options, but for things like the ".2" part you need to see the referenced IEEE printf() description. Ron C.