Sign in to follow this  
Followers 0
anixon

StringFormat

7 posts in this topic

#1 ·  Posted (edited)

Using this code:

$Value = StringFormat('%.2f', 0.00)

FileWriteLine($File, $Value)

$Value = StringFormat('%.2f', 10.00)

FileWriteLine($File, $Value)

This is achieved

0.00

10.00

What is the magic to format the numbers to appear in correct column format

Ant..

Edited by anixon

Share this post


Link to post
Share on other sites



Using this code:

$Value = StringFormat('%.2f', 0.00)

FileWriteLine($File, $Value)

$Value = StringFormat('%.2f', 10.00)

FileWriteLine($File, $Value)

This is achieved

0.00

10.00

What is the magic to format the numbers to appear in correct column format

Ant..

Try this, although it will only really give you what you want with a mono spaced font

$Value = StringFormat('%.2f', 0.00)
FileWriteLine($File, $Value)
$Value = StringFormat('%.2f', 10.00)
FileWriteLine($File, $Value)

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Try this, although it will only really give you what you want with a mono spaced font

$Value = StringFormat('%.2f', 0.00)
FileWriteLine($File, $Value)
$Value = StringFormat('%.2f', 10.00)
FileWriteLine($File, $Value)

I am using the same code as per your example so I guess the question is what is a typical mono font. I am currently using

Global $Font = "times new roman", $FontSize = 10, $FontWeight = 400

Ant..

Share this post


Link to post
Share on other sites

I am using the same code as per your example so I guess the question is what is a typical mono font. I am currently using

Global $Font = "times new roman", $FontSize = 10, $FontWeight = 400

Ant..

Sorry I posted the wrong code in my first reply.

$Value = StringFormat('%6.2f', 0.00)
FileWriteLine($File, $Value)
$Value = StringFormat('%6.2f', 10.00)
FileWriteLine($File, $Value)

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Sorry I posted the wrong code in my first reply.

$Value = StringFormat('%6.2f', 0.00)
FileWriteLine($File, $Value)
$Value = StringFormat('%6.2f', 10.00)
FileWriteLine($File, $Value)

What does the 6 actually do in '%6.2f' as it does appear to have an explaination within the documentation. I noticed that 0 as a flag can be used as width padding.

Ant..

Share this post


Link to post
Share on other sites

What does the 6 actually do in '%6.2f' as it does appear to have an explaination within the documentation. I noticed that 0 as a flag can be used as width padding.

Ant..

The "6" is the total number of characters.

;
$Value = StringFormat('%6.2f', 0.00)
ConsoleWrite($Value & " <== 6 characters in total" & @CRLF)

$Value = StringFormat('%6.2f', 123.56)
ConsoleWrite($Value & " <== 6 characters in total" & @CRLF)

$Value = StringFormat('%7.2f', 123.56)
ConsoleWrite($Value & " <== 7 characters in total (1st character a space)" & @CRLF)
;

Share this post


Link to post
Share on other sites

The "6" is the total number of characters.

;
$Value = StringFormat('%6.2f', 0.00)
ConsoleWrite($Value & " <== 6 characters in total" & @CRLF)

$Value = StringFormat('%6.2f', 123.56)
ConsoleWrite($Value & " <== 6 characters in total" & @CRLF)

$Value = StringFormat('%7.2f', 123.56)
ConsoleWrite($Value & " <== 7 characters in total (1st character a space)" & @CRLF)
;

Ahhh that makes sense to ensure the correct justification you just increase the number to accommodate thousands, 10's of thousands etc. So much to learn so little time. Appreciate your explaination Ant.. an AusVicMex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0