6 Replies Latest reply on Jan 22, 2008 2:33 AM by kruse

Alignment of numbers on canvas

I use a canvash to position some labels.
The first label contain a text and the next contain a number.
Because I use X and Y to position them it looks like this

Proteins 25.10
Carbs 101.25
Fats 68.90
Kcals 1125,50

But I would like to allign on the decimal seperator like this

Proteins 25.10
Carbs 101.25
Fats 68.90
Kcals 1125.50

How do I do that?
I wouls still like to use canvash because I can put each line very close to eatch other.
• 1. Re: Alignment of numbers on canvas
Hey

I would prefer to use a Datagrid with four columns. the first colum has the text inside with textalignment left, the second should have the numbers left of the decimal seperator with textalignment right, the third only should contain the decimal seperator and the last one the numbers right of the seperator with textalignment left

don't forget do adjust all the lines, border and backgroundcolors of the datagrid that it will look like a normal canvas
• 2. Re: Alignment of numbers on canvas
Hi

How would you split the number?
• 3. Re: Alignment of numbers on canvas
There are severel ways:

First: Cast the Number into a String and then use the function split (attention: if you want to split with the point you have to take care that the delimter parameter of the split function is a pattern so you have to escape the point, I think you can do this with the backslash, but to get sure read the docs about pattern)

Second: try to solve this problem with mathematic: To do this use the classes Math and/or Number
• 4. Re: Alignment of numbers on canvas
I think that it would be mutch easyer to just make 2 columns and the put the string in the first column left alligned and then the number in the second column right alligned.
Then I just have to assure that all the numbers have got the same number of decimals.
• 5. Re: Alignment of numbers on canvas
Sure that's also a solution, I don't know your requirements for your application, but if you do like you said before, you have to take care that every different number has the same width (I mean that the font which you are displaying your text is a non-proportional font)
• 6. Re: Alignment of numbers on canvas
I see. That solution will only work if the font is non-proportional.
I think that I will try you solution with the math.
Thanks for you help