|
-
Nov 29th, 2016, 02:46 PM
#1
Thread Starter
Member
[RESOLVED] Windows 10 - Unexplained InvalidCastException ???
I have some code the decrypts some text and then casts it to a decimal value. With windows 7 it works fine, but on another computer running windows 10 it throws an exception stating "83.96" cannot be cast to type decimal??
Code:
dim deciphertext as string = "83.96"
dim dec_value as decimal = CDec(deciphertext) 'Throws exception here
How is this even possible? Some google answers suggest is might be something to do with the cultureinfo.currentculture on this specific machine, but the answers are very vague.
Any help on where to start repairing would be greatly appreciated.
Last edited by Vegito_ZA; Nov 29th, 2016 at 02:55 PM.
Reason: Typo
-
Nov 29th, 2016, 06:05 PM
#2
Re: Windows 10 - Unexplained InvalidCastException ???
If you change "83.96" to "83,96" does it work then? If so then it is a culture issue. If you use Convert.ToDecimal or Decimal.Parse then you get to specify a format provider so you won;t implicitly rely on the current culture. Personally, I only use CDec and the like for casting rather than converting, i.e. I only use it when the object is already type Decimal. There cannot be any issue in that case.
-
Nov 30th, 2016, 02:22 PM
#3
Thread Starter
Member
Re: Windows 10 - Unexplained InvalidCastException ???
@ jm, thanks for the tip. Yup it's a culture thing. Windows 10 allows a user to customize the way numbers are shown and in this specific case, the user chose " , " as the decimal separator. The moment I changed that setting, the exception went away.
Tags for this Thread
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
|