|
-
Jun 18th, 2007, 02:29 AM
#1
Thread Starter
Lively Member
[RESOLVED] Currency datatype
I have created small business application where I have used currency data type. Everything works fine with currency data type until I change system regional settings (date format, currency format ect.). All the calculations on currency data type also changed according to regional settings which gives me wrong calculation on currency. How can I work on specify regional settings even if the system regional setting is changed.
-
Jun 18th, 2007, 03:11 AM
#2
Re: Currency datatype
explain and give an example of how you are doing your calculation. The datatype should be unaffected by regional settings. The way it is displayed on screen however is affected by them, and how the format command works is.
-
Jun 18th, 2007, 03:55 AM
#3
Thread Starter
Lively Member
Re: Currency datatype

This what i am getting before changing the regional settings.
i am getting the exact amount i have specified

and this the value i am getting after changing regional settings to Germany
-
Jun 18th, 2007, 04:04 AM
#4
Re: Currency datatype
ok why are you using val on a number to start with? It already is a number.
use ccur to convert it to currency
-
Jun 18th, 2007, 04:08 AM
#5
Re: Currency datatype
The problem is not in the currency datatype, but in the Val function.
You used it completely unnecessary here.
Val expects a string as parameter. VB will convert the value to a string for you, and will use the regional settings for this. If the decimal seperator is a comma, the string will be "23,44"
Val however, is not regional settings aware, and will only recognize a point as decimal seperator. So it will stop after 23.
In this case there is no reason to use Val. Just remove it. It only causes an extra implicit conversion (because the parameter is not a string), an exptra function call (Val is not necessary), and a second implicit conversion (Val returns a double and not a decimal)
Your assigment will be
Curr = 23.44
Or if you want to be precise, you can use the currency declaration character, so no implicit conversion will occur anymore.
Curr = 23.44@
-
Jun 18th, 2007, 04:11 AM
#6
Thread Starter
Lively Member
Re: Currency datatype
let me make it simple
vb Code:
Dim Curr As Currency
Curr = 22.22
'now Curr will return 22,22 not 22.22
'bcuz of regional settings
now if i have to compare Curr with value "22.22" it will return false bcuz of changed separator how can i avoid this?
-
Jun 18th, 2007, 04:17 AM
#7
Re: Currency datatype
This is not true.
If it was true what you said, then the messagebox will not be shown in this code:
Code:
Private Sub Command1_Click()
Dim c As Currency
c = 22.22
If c = 22.22 Then MsgBox "Yes"
End Sub
The problem only occurs when you are comparing strings.
-
Jun 18th, 2007, 04:22 AM
#8
Thread Starter
Lively Member
Re: Currency datatype
what if i have to compare c with string?
-
Jun 18th, 2007, 05:00 AM
#9
Re: Currency datatype
Then don't compare it to a string, cast the string accordingly with CCur() function instead of Val(). Or work with strings with no thousands separator using Format().
-
Jun 18th, 2007, 06:23 AM
#10
Thread Starter
Lively Member
Re: Currency datatype
thanks Frans C and leinad31
-
Jun 18th, 2007, 10:50 AM
#11
Re: [RESOLVED] Currency datatype
yeah thanks for saying exactly what i did: Use CCur
-
Jun 18th, 2007, 08:33 PM
#12
Re: [RESOLVED] Currency datatype
Yes, for the record it was Lord Orwell's idea. Please don't forget to give him the rep points due to him.
-
Jun 18th, 2007, 09:00 PM
#13
Re: [RESOLVED] Currency datatype
hey can i help it most of my posts predate ratings? 
leave the board for 2 years and everyone else has green bars!
-
Jun 19th, 2007, 01:06 AM
#14
Re: [RESOLVED] Currency datatype
I know what you mean.
My most active years on this board are years ago.
But slowly I am catching up with the others.
-
Jun 19th, 2007, 01:21 AM
#15
Re: [RESOLVED] Currency datatype
me too. i've got about 50 pts in the last month. I love it when someone with huge post #s rates me. I have a bunch of kudos from people under 20 posts.
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
|