Reputation: 155
I have yet to confirm this is an actual bug but at this point I'm starting to think it is. Our old product we still have support for has caused some issues with data. This product is built off of VB6. The issue in question is regional settings and number formatting.
There are two quick examples I can write out here that can be ran on your own computer that should validate this issue. Your regional settings need to be configured for Greece as well. Before running this.
public sub main ()
dim sTwo as string, sThousand as string
sTwo = "2.0"
sThousand = "1,000"
debug.print "should be 2.0 or 2"
debug.print sTwo
' "2.0"
debug.print clng(sTwo)
' 20
debug.print cdbl(sTwo)
' 20
debug.print format(sTwo)
' 20
debug.print "\nshould be 1000.0 or 1000"
debug.print sThousand
' "1000"
debug.print clng(sThousand)
' 1
debug.print cdbl(sThousand)
' 1
debug.print format(sThousand)
' 1
end sub
Im just looking for some validation that this is actually occuring for other users and not just on my machine or coworkers with this machine. However, if someone knows of a workaround for now that would be great. Im currently trying to look up how to force number formatting a certain way.
From Laneville's suggestions
?formatnumber("2.0", 1, vbUseDefault, vbFalse, vbTrue)
20,0
?formatnumber("2.0", 0, vbUseDefault, vbFalse, vbTrue)
20
?formatnumber("2.0", 0, 0, vbFalse, vbTrue)
20
?formatnumber("2.0", 0, 0, vbFalse, vbfalse)
20
Upvotes: 0
Views: 796
Reputation: 10855
I would use the VB6 Format$ function to convert a numeric type to a string for display to a user. Keep numeric values as numbers internally, don't store them as string, that is the wrong datatype to hold numbers.
Assuming your number variables are storing the value you expect, Format$ should work for formatting for display. It is stated to be locale aware. Your code above is not specifying a format expression, take a look at what is available:
Here is a relevant excerpt:
(.)
Decimal placeholder. In some locales, a comma is used as the decimal separator. The decimal placeholder determines how many digits are displayed to the left and right of the decimal separator. If the format expression contains only number signs to the left of this symbol, numbers smaller than 1 begin with a decimal separator. To display a leading zero displayed with fractional numbers, use 0 as the first digit placeholder to the left of the decimal separator. The actual character used as a decimal placeholder in the formatted output depends on the Number Format recognized by your system.
Upvotes: 1
Reputation: 5031
Take a look at the FormatNumber function, you can specify the number of digits after decimal (1000.0 vs 1000) and if digits are to be grouped (1,000 vs 1000).
FormatNumber(1000, 0, vbUseDefault, vbFalse, vbFalse)
This returns 1000.
FormatNumber(1000, 0, vbUseDefault, vbFalse, vbTrue)
This returns 1,000.
Upvotes: 1