This may be an easy problem but it has me perplexed. I have a series of text fields arranged vertically in a window. Each text field contains an amount, and I want them to have decimal alignment in the display.
Some values are negative: (123.45) and some are positive: 123.45. I want to add a space after the positive numbers so that the decimals will align between positive and negative numbers.
Adding a space to the string does not seem to work (chr(32)). There doesn’t seem to be a way in the format command to add a blank space, unless I am missing something. Excel allows a placeholder for positive numbers to force decimal alignment. How do you do that in Xojo?
This format string works for me “#.00\ ;#.00-;0.00” - note the backslash followed by a space at the end of the positive format. You’ll also want to use a mono spaced font for example courier to get the alignment exactly correct.
You could also consider using a Listbox to display your data. You can set a decimal alignment on columns & cells using that.
Tried a mask with a space after the backslash. Tried a monospaced font like Courier also. Neither worked.
It seems Xojo trims the right side of a string. All spaces are removed before displaying text on the screen.
This is true of both Labels and TextFields. Example below: The left column are TextFields with monospaced font Courier; the right are Labels with font StoneSans (which is not a monospaced font but the number characters are monospaced).
You need to find out if it’s the text field that’s stripping the space, or the format command. Check to see if the rightmost character is a space before sending it to the text field. My suspicion is that it’s the format command doing this, because the format command has always been a bit wonky.
If the problem turns out to be the text field, then a workaround could be to replace the rightmost space with a non-breaking space, Unicode U+00A0.
I tested this (with chr(160)) and it looks ok when the TextField has focus but not when the focus is not on that field (the non-breaking space is removed). Labels work ok. At least on my mac.
The whole issue would disappear if instead of using parenthesis, negative would appear in another color (Red for instance), or with the minus sign : -123.45.
I agree with that, Michel, and if you look at my earlier example, I did make the negative values red.
But it still seems to me that the concept of formatting of a number is not “new territory” and while I am always willing to use “workarounds” there shouldn’t be a restriction on how an accounting display of numbers is shown. To an accountant, this is a significant issue which is solved in Excel with a simple underscore [ _ ] as a placeholder. Same should be true in Xojo.