|
-
May 17th, 2008, 05:46 AM
#1
Thread Starter
Junior Member
how to use both "." and "," as signs(operators) for decimal numbers?
in the textboxes of my form,the project accepts as decimal sign the comma ",".
what's the code to make it work with both "," and "." ? that way, i am avoiding error messages and unsufficiencies in the calculations that my form does.
-
May 17th, 2008, 06:00 AM
#2
Re: how to use both "." and "," as signs(operators) for decimal numbers?
I'm not sure I know your exact situation. You didn't provide any sample code or a detailed description. I can take a guess though. If I'm wrong no harm, right?
You're probably dealing with what Windows considers "different locales." One thing that varies from one locale to another is the choice of "decimal point" symbol. In many places this is "." while in others it may be "," instead.
The ancient Val() function really exists for compatability with much earlier Microsoft Basic products. It always considers "." to be the indicator for the decimal point in a string it converts to a numeric value.
Newer alternatives exist such as CSng(), CDbl(), and CCur() and these are all "locale aware" in the sense that if the user's locale uses "." they use "." and if the user's locale uses "," then they will consider "," to be the decimal point indicator.
Does this help?
-
May 17th, 2008, 06:15 AM
#3
Frenzied Member
Re: how to use both "." and "," as signs(operators) for decimal numbers?
Just allow both of these to be entered but only ONCE. If not then your program will confuse digit separators and decimal points.
5,444.678
Could be five thousand, four hundred and forty four point six, seven, eight. Or it could be five point four, four, four, six, seven, eight. Or even 5 point four, four, four point six, seven, eight - which as we know doesnt exist.
Allow just one symbol to avoid this.
-
May 17th, 2008, 06:35 AM
#4
Re: how to use both "." and "," as signs(operators) for decimal numbers?
If you want use both "." and "," as decimal separators at the same time won't that potentially cause problems rather than solve them?
What is 5,444? Is it five and a bit or five thousand and a bit?
I would have thought sticking with the separator dictated by locale is probably the best bet.
As Dilettante says there are a few functions that can convert a numerical string to a number and visa versa, some are locale aware some are not. It's important not to mix these up i.e. using cDbl() to get a number and Str() to convert it back to a string will mess things up if the period is not your separator.
As well as Val(), Format() and Str() are also not locale aware.
cDbl(), cCur(), cStr(), FormatNumber(), IsNumeric(), etc. all are
-
May 17th, 2008, 07:02 AM
#5
Thread Starter
Junior Member
Re: how to use both "." and "," as signs(operators) for decimal numbers?
so milk,
if i got it right you suggest to leave "," as decimal separator so that it will not have problems with thousands and so goes...
ok!!!
-
May 17th, 2008, 07:45 AM
#6
Re: how to use both "." and "," as signs(operators) for decimal numbers?
Not so much leave the "," but allow the locale to dictate it. If your program uses locale aware conversions and I was to use your program with my UK locale it would automatically expect a period as the separator.
Just to be clear the locale only affects numbers in string form, numbers internally always use the period.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|