473,585 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Decimal separator/locale and keypress event

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 DecimalSeparato r()

{

char c;

System.Globaliz ation.CultureIn fo ci =

System.Globaliz ation.CultureIn fo.CurrentUICul ture;

System.Globaliz ation.NumberFor matInfo ni =
(System.Globali zation.NumberFo rmatInfo)

ci.NumberFormat .Clone();

c = (ni.NumberDecim alSeparator.ToC harArray())[0];

return c;

}
Nov 16 '05 #1
2 11043
Hi Claire,

Well, you could declare

using System.Globaliz ation;

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

using SystemGlobaliza tion;

public static char DecimalSeparato r()
{
return CultureInfo.Cur rentCulture.Num berFormat.Numbe rDecimalSeparat or.ToCharArray( )[0];
}

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Haven't tested yet, but thanks Morten
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12107
by: Ordz | last post by:
I want to write a program that will take a decimal with up to 4 places and convert it to 1/16 ths. I can sort of do that with: n = 375 * 16 / 1000 Print n; "/16" I am planning to use an input box to enter the number with no decimal point. But I don't know how to get a count of the digits in the denominator. I will also round off any...
8
15481
by: SAN CAZIANO | last post by:
i have to do in the onkeypress or in onchange the float (real) field validation I try something: function ValidaCampo(nomeCampo,TotInteri,TotDecimali) { DecimalPos=NomeCampo.value.Indexof(','); Lungh=TotInteri+TotDecimali+1; //sum the ineger + decimal + decimal separator
4
8940
by: John Bowman | last post by:
Hi, A couple Q's , so I've come to the experts<g>. 1) I need a definitive answer to the following debate. I've got a couple developers who disagree on the following question. We've got an XML file of numerical data results where it could contain values such as: <RESULT>0.12345</RESULT> when created in English, but it could contain:...
3
4011
by: GP | last post by:
Decimal.Parse("100,5") returns 1005 when it should throw an InvalidFormatException. The locale is US therefore the "," is a thousand separator. Even if the parser confused it for the decimal separator it should return 100.5. Maybe this bug is already logged but I couldn't find it on MSDN. -- Best regards, Gianluca Pivato --
5
7685
by: trawlerman | last post by:
Hi all, C# newbie after migrating from VB. I wish to have only valid numbers entered into a txtbox . i.e only one decimal point. ///////////////////My VB code for this is: Private Sub txtGcost_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57, 8 Case 46 If InStr(txtGcost.Text, ".") 0 Then
52
1565
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is...
2
22619
by: apattin | last post by:
Hi all, I have a table containing MEASURE DOUBLE. I want to SELECT measure FROM mytable WHERE <condition> If measure = 1860.45, I get: '1,860.45'. How can I strip the comma? I tried: DECIMAL(measure,20,5) still has the comma
2
6352
by: pax | last post by:
Hello there! Here is my problem, in the simplest scenario: - an Access 2000 format database (created with Access 2003) - a simple table that contains one single field defined as Number, Decimal, 18,2 - VS2005 standard, C# - a data source / dataset that cotains that simple Access table - a DataGridView, created by drag and drop, with all...
2
3832
by: boder | last post by:
I've set US locale with ',' (comma) as a decimal separator. My code : var xmlObject = new ActiveXObject("MSXML2.DOMDocument.3.0"); xmlObject.setProperty("SelectionLanguage", "XPath"); var datasetNode = xmlObject.createElement("dataset"); datasetNode.setAttribute("name", "test"); var recordNode =...
0
7836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8336
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7950
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.