Re: Weird CultureInfo - DateTime.Parse() and Decimal.Parse()
- From: "Claes Bergefall" <louplou@xxxxxxxxxxxxx>
- Date: Wed, 20 Sep 2006 12:25:00 -0400
The results are correct, you're just not interpreting them correctly. See
inline
"Rico" <ras_nas@xxxxxxxxx> wrote in message
news:Xns9844EAF257147rasnasyahoocom@xxxxxxxxxxxxxx
Hello Everyone,
I observed something strange in some quick testing code:
void Button1Click(object sender, System.EventArgs e)
{
CultureInfo culture = new CultureInfo("th-TH", false);
tbxDisplayResult.Text = DateTime.Parse(tbxInputArea.Text,
culture).ToString("yyyy MMMMMMMMMM dd");
}
with tbxInputArea.Text of "10.9.2006",
tbxDisplayResult.Text is displayed as "1463 September 10".
Thailand might have taken huge steps backwards over the past 24 hours, but
I doubt it's steps of that magnitude, isn't it?
For starters your input data is incorrect. Thailand uses '/' as date
separator. Secondly, Parse actually succeedes here (even though you feed it
with invalid data). What you failed to realize is that Thailand uses a
calendar that is offset by 543 years, so Sept 10, 2006 in the Thai calendar
is the same as Sept 10, 1463 in the Gregorian calendar.
void Button1Click(object sender, System.EventArgs e)
{
CultureInfo culture = new CultureInfo("ms-MY", false);
tbxDisplayResult.Text = Decimal.Parse(tbxInputArea.Text,
culture).ToString("N2");
}
tbxInputArea.Text of "1,973.00" results in a parsing error,
whereas with tbxInputArea.Text of "1.973,00" parsing succeeds.
I doubt that Malaysia uses decimal separators the way the Germans do.
Stop doubting and look it up instead (they do in fact use ',' as decimal
seprator).
Is that a bug in the framework?
No
/claes
.
- Follow-Ups:
- References:
- Prev by Date: Re: How to put a clickable button on a PropertyGrid ?
- Next by Date: Re: Any ideas on this?
- Previous by thread: Re: Weird CultureInfo - DateTime.Parse() and Decimal.Parse()
- Next by thread: Re: Weird CultureInfo - DateTime.Parse() and Decimal.Parse()
- Index(es):