If I run this:
dim s as string = "#,###,###,###.###;-#,###,###,###.###;"
MsgBox( Format( 50, s ) )
I get the message box containing:
but I want it to contain
(i.e. without the decimal point.)
What am I doing wrong?
If I run this:
dim s as string = "#,###,###,###.###;-#,###,###,###.###;"
MsgBox( Format( 50, s ) )
I get the message box containing:
but I want it to contain
(i.e. without the decimal point.)
What am I doing wrong?
Frist, you don’t need such a long format string. This would do the same:
“#,#.###;-#,#.###”
If some values might have a decimal and others not and you never want the decimal, use:
“#,#;-#,#”
If it’s the case where you only want the decimal point if a decimal exists, Format won’t do that. Use code like this:
dim s as string = Format( v, "#,#.###;-#,#.###" )
if s.Right( 1 ) = "." then
s = s.Left ( s.Len - 1 )
end if
MsgBox s
Curious. Could’ve sworn it worked differently in RealStudio but I’ve just tested it and it’s exactly the same. Thanks, Kem!
I just realized that the code I gave you isn’t international-savvy. You should strip either a dot or comma if it appears as the last character.
static rxStripper as RegEx
if rxStripper is nil then
rxStripper = new RegEx
rxStripper.SearchPattern = "\\D$"
end if
dim s as string = Format( v, "#,#.###;-#,#.###" )
s = rxStripper.Replace( s )
That will strip any character from the end of the string that isn’t a digit.