[fxruby-users] FXTextField and number of digits after decimal point

Lyle Johnson lyle at lylejohnson.name
Tue Nov 11 19:58:10 EST 2008

On Nov 11, 2008, at 11:25 AM, Michèle Garoche wrote:

> My question is: Is there a way to use either a TEXTFIELD_INTEGER or  
> a TEXTFIELD_REAL without losing digits after the decimal point?

The lack of display precision has to do with the fact that you're  
using an FXDataTarget to update the value of the text field.

When the FXTextField sets its text from the double-precision float  
value that it gets from the FXDataTarget, it uses a fixed format like:

	sprintf(str, "%.*G", 6, value);

To use a custom formatting, you'd need to stop using FXDataTarget and  
instead use a combination of SEL_COMMAND and SEL_UPDATE, e.g.

	@value_value.connect(SEL_COMMAND) do
		@value = @value_value.text.to_f

	@value_value.connect(SEL_UPDATE) do
		@value_value.text = @value.to_s # or however you want to format it

Hope this helps,


More information about the fxruby-users mailing list