473,408 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Check Decimal Places in C#

Hi all,

I have a textbox to let user to input digits. After they input, I want to count how many decimal places they input. How can I do?

Regards,

Nov 16 '05 #1
3 10931
Not sure if it is the best method, but the following works:

<textboxid>.Text.Length - (<textboxid>.Text.IndexOf(".")+1)

"Philip" <Ph****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Hi all,

I have a textbox to let user to input digits. After they input, I want to count how many decimal places they input. How can I do?
Regards,

Nov 16 '05 #2
Hi,

It works... only if there's no empty places in text box,
and it works for CultrureInfo with "." as a number decimal
separator!

Some changes:

string numberStr=<textboxid>.Text.Trim();
string decSeparator=NumberFormatInfo.CurrentInfo.NumberDe cimalSeparator;
// or "NumberFormatInfo.CurrentInfo.CurrencyDecimalSepar ator"

int index=numberStr.IndexOf(decSeparator);
int decPlaces;
if( index==-1 ) {
decPlaces=0;
}
else {
decPlaces=numberStr.Length - (index+decSeparator.Length);
}

Cheers!

Marcin
Not sure if it is the best method, but the following works:

<textboxid>.Text.Length - (<textboxid>.Text.IndexOf(".")+1)

"Philip" <Ph****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Hi all,

I have a textbox to let user to input digits. After they input, I want to


count how many decimal places they input. How can I do?
Regards,


Nov 16 '05 #3
Thanks a lot. It works.

"Marcin Grzębski" wrote:
Hi,

It works... only if there's no empty places in text box,
and it works for CultrureInfo with "." as a number decimal
separator!

Some changes:

string numberStr=<textboxid>.Text.Trim();
string decSeparator=NumberFormatInfo.CurrentInfo.NumberDe cimalSeparator;
// or "NumberFormatInfo.CurrentInfo.CurrencyDecimalSepar ator"

int index=numberStr.IndexOf(decSeparator);
int decPlaces;
if( index==-1 ) {
decPlaces=0;
}
else {
decPlaces=numberStr.Length - (index+decSeparator.Length);
}

Cheers!

Marcin
Not sure if it is the best method, but the following works:

<textboxid>.Text.Length - (<textboxid>.Text.IndexOf(".")+1)

"Philip" <Ph****@discussions.microsoft.com> wrote in message
news:4E**********************************@microsof t.com...
Hi all,

I have a textbox to let user to input digits. After they input, I want to


count how many decimal places they input. How can I do?
Regards,


Nov 16 '05 #4

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

Similar topics

17
by: Craig Bailey | last post by:
Someone please explain what alternate universe I fell into this afternoon when PHP started telling me that 2 doesn't equal 2. Not sure about you, but when I run this, it tells me 59001.31 doesn't...
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
3
by: Brent Bortnick | last post by:
Does anyone know how to find out the number of decimal places a number has. I need this info so that i can round to 3 decimal places if the number has 3 decimal places or to 2 decimal places if...
2
by: Carl G | last post by:
I am storing a 0.000 a System.Decimal in a DataRow. On retrieval the value is only 0 without the three decimal places. It looks like the Get property returns System.Decimal.Zero, but why???? I...
4
by: italia | last post by:
I changed the Fieldsize Property from text to Long Integer and Decimal Places = 6. I had decimals in the original field. But after the transfer, the digits after the decimals are gone. Now...
8
by: nick | last post by:
printf("%lf",3.25); the result is 3.25000 i want the answer correct to 3 decimal places What should i do? thanks!
3
by: NH | last post by:
How can I check the value of a textbox has no more than 2 decimal places? I already check that the value is numeric, but how do I check that it is not 0.223 or .022 etc. I only want to allow up...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
3
by: David | last post by:
Any ideas why this statement: mBalanceChange = Double.Parse(strCurrentBalance, Globalization.NumberStyles.AllowThousands Or Globalization.NumberStyles.AllowDecimalPoint) - mBalanceDouble ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.