Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
Im using regular expression to get values such as (16.00 + 28.66 = 44.66) as 44.66 ,(26.00) as 26.00
I have trouble to display data when its just(99) as 99 without any decimal.

I have used the below code to till now

C#
string amount = DropDownList1.SelectedItem.Text;
        Regex regex = new Regex("(\\d+\\.\\d{2})(?=\\))", RegexOptions.Multiline | RegexOptions.CultureInvariant
   | RegexOptions.IgnorePatternWhitespace
   | RegexOptions.Compiled
   );



Someone please tell me how can i display a value without any decimal..
Eg-(99) as 99

Thanks.
Posted

1 solution

Try:
C#
string amount = DropDownList1.SelectedItem.Text;
        Regex regex = new Regex("(\\d+(\\.\\d{2})?)(?=\\))", RegexOptions.Multiline | RegexOptions.CultureInvariant
   | RegexOptions.IgnorePatternWhitespace
   | RegexOptions.Compiled
   );

Or
C#
string amount = DropDownList1.SelectedItem.Text;
        Regex regex = new Regex("(\\d+(\\.\\d{1,2})?)(?=\\))", RegexOptions.Multiline | RegexOptions.CultureInvariant
   | RegexOptions.IgnorePatternWhitespace
   | RegexOptions.Compiled
   );
Which will also allow (99.9)
 
Share this answer
 
Comments
Maciej Los 1-Mar-14 6:51am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900