How do I print currency in Graphics?

In short, how do I align the currencies values vertically ?
7.3
12.26

?

Use a Monospaced font and add spaces to align.

1 Like

Use a non-proportional font like Courier.
decide upon the location of the right hand edge

Then .drawstring the value at {righthand edge position} - (g.stringwidth (thevalue)}

OR

pick a left position, and draw spaces plus the value

g.drawstring right(" " + thestringvalue,6) , leftposition, topposition

Here is some code. Put it in the Open-event of a Popup-Menu to get monospaced fonts on the top of the menu:

dim PropFonts(-1) As string
const smallstr = "IIIIIIIIII"
const wideStr  = "WWWWWWWWWW"

dim p As picture = New Picture(1,1,32)
if p=nil Then return

dim g As graphics = p.Graphics
g.TextSize = 12

dim maxFont As integer = FontCount - 1
for i as integer = 0 to maxFont
  dim fName As string = Font(i)
  g.TextFont = fName
  if (g.StringWidth(smallStr) - g.StringWidth(wideStr))=0 then
    popupMenu1.AddRow fName
  else
    PropFonts.append fName
  end
next

popupMenu1.addSeparator

maxFont = Ubound(PropFonts)
for i as integer = 0 to maxFont
  popupMenu1.AddRow PropFonts(i)
next

Thank you for the suggestion, but that looks like “Programming in the 60s…” to me.

Creating a bill with a Courier type font ?

I am stoned (and I do not smoke since 55 years)…

Edit:
BTW: you mean to do that from the currency x tab value… That I can do (I think).
My lunch meal arrived, I will implement later.

That doesn’t mean it’s wrong.

If you use a proportional font,
111111.11 does not line up with
888888.88
This is what fonts like Courier are designed for.

If you want to use a proportionally spaced font .you would need to place each individual number in a calculated position.
That looks like ‘hard work’ to me.

1 Like

Well, there are much more monospaced fonts available. Use my code to see what can be used. I’m no friend of Courier, too :wink:

IMHO, Andale Mono or Menlo look much better.

Still looks strange to me, but OK.

Thank you for the advice.

.drawstring of the integer part at the left of the desired dot position
.drawstring of the fractionnal part at the right of the dot position
using this, the dot are aligned, and you can use any font you want
but the digits may be not aligned between then until you use a non-proportionnal font.

1 Like

Jean-Yves:

this is the needed answer !!!

THANK YOU !


Example of printing using System (default) Font.

Looks fine, excepted lines are in reverse order for unknow reason.

Original data:

I do not took time to adjust the align for the last two columns ! Doh…


with currency align in the ListBox.

With comma, the decimal part were removed… so I used a dot.

Look for a typeface that has “tabular numerals”, which are basically monospaced numbers. Then you can simply right-align your currency values and they will line up.

Most fonts, except San Francisco, have monospaced (non proportional) digits. So you could do the same with Arial or Times.

In a listbox (API 1) you can use the combination of
ListBox.ColumnAlignment = AlignDecimal
ListBox.ColumnAlignmentOffset = SomeValue

(or the equivalent Cell Properties- well methods really)

to decimal align numbers in cells… No need to draw the parts of the numbers yourself

-Karen

Already done. Splitting the value is for printing, not displaying.