Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format float decimals when using Value With Pattern binding?

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?

like image 239
anna Avatar asked Mar 14 '11 17:03

anna


People also ask

How do you write a float value up to 2 decimal places?

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 %.

Can a float value have decimal numbers?

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.

What is floating decimal format?

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.


1 Answers

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.

like image 174
Evan Avatar answered Sep 18 '22 12:09

Evan