Text Alignment Left/Right

I have a problem with text alignment left/ right.
I was thinking, alignment left means that text starts at the left side of the text of the X,Y coordinates and that alignment right ends of the X,Y coordinates.
Alignment left/ right works only when the text is longer then the textWrapWidth().
My problem; I find out to present values with a fraction part of, for instance, 2 digits.
If I want to present several values in a column, then I want present this values with alignment “right” (within text(var, x, y))?. I want to have the dots on the same column place.

Simeon, how can I do this (on a simple way, without a lot of software)? or is this an option for the next update?
GW basic has the print using instruction, like print using, for instance, xxxxx.xx

Greetings, Dirk.nl

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
    font("Inconsolata")
    fontSize(24)
    print(string.format("%6.2f",131071.99))
    print(string.format("%6.2f",131072.99))
    print(string.len(string.format("%5.2f",9.9)))
    --textAlign(LEFT)
    textMode(CORNER)
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness
    strokeWidth(5) 

    -- Do your drawing here
    x = 0
    t = string.format("%5.2f",x) 
    text(t,200-textSize(t),HEIGHT-(fontSize()))
    text(string.len(t),300,HEIGHT-(fontSize()))
    text(textSize(t),500,HEIGHT-(fontSize()))
    for i = 2,10 do
        x = math.random(131071) + math.random()
        t = string.format("%5.2f",x) 
        text(t,200-textSize(t),HEIGHT-(i*fontSize()))
        text(string.len(t),300,HEIGHT-(i*fontSize()))
        text(textSize(t),500,HEIGHT-(i*fontSize()))
    end
end 

Most of the code is for demonstration. Three main points:

  1. string.format(“%5.2f”,x) is like xxxxx.xx (or 99999V99 in COBOL). It is based on the printf command

  2. textSize(t) is the length of the text, so to align RIGHT corner I used CORNER and subtract the length

  3. 131071.99 is as high as you can go down to the penny

Ok. … 4 :slight_smile:

This doesn’t work for all fonts

You can get it to work for all fonts by measuring the substring before the dot, and using that to get the correct X position for the text.

Okay, lpda41001 and Simeon!
The “%f” I already figure it out.
Yes, of course, I must use textSize(). lpa41001, I have tested your example program, I understand the use of textSize()

Thanks, Dirk.nl