I have an NSTextField, which is bound to a float value through Interface Builder via "Value with Pattern" field. The default display pattern is %{value1}@
Is there any way I can modify that line to have my output formatted to 2 decimal places? Or is that only possible through code?
format("%. 2f", 1.23456); This will format the floating point number 1.23456 up-to 2 decimal places, because we have used two after decimal point in formatting instruction %.
If doing math with floats, you need to add a decimal point, otherwise it will be treated as an int. See the Floating point constants page for details. The float data type has only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point.
Definition of floating decimal : a system of decimal point placement in an electronic calculator in which the decimal point is free to move automatically across the display in order to allow the maximum number of decimal places in the readout.
I've just been trying to do this, as well. You can drag a Number Formatter from the object library on top of the object you want to format. One of the property pages for the formatter allows you to choose from a list of predefined formats, or choose custom and make your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With