Decimal separator/locale and keypress event

C

Claire

I'm monitoring key presses in an edit box on a pocket pc device.
It's for floating point numbers and Im allowing '-', '0'..'9', #8 plus
decimal point character.
Ive a function that should return a char representing the decimal point for
this locale.
Not knowing what I was doing on .net, I did a google and came up with some
code that I changed as follows.
It looks really ugly and I wondered if I needed to do all this to read back
a decimal separator value. Please would someone change my code. I don't know
if it works, it returns a '.' OK for my english pocketpc, but I wouldn't
know how to set up
pocketpc to change locale for test purposes.
public static char DecimalSeparator()

{

char c;

System.Globalization.CultureInfo ci =

System.Globalization.CultureInfo.CurrentUICulture;

System.Globalization.NumberFormatInfo ni =
(System.Globalization.NumberFormatInfo)

ci.NumberFormat.Clone();

c = (ni.NumberDecimalSeparator.ToCharArray())[0];

return c;

}
 
M

Morten Wennevik

Hi Claire,

Well, you could declare

using System.Globalization;

and save a couple of words, and put it all on a single line.

using SystemGlobalization;

public static char DecimalSeparator()
{
return CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator.ToCharArray()[0];
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top