Home Dashboard Directory Help
Search

Extend double.Parse to interpret Percent values by omjbe


Status: 

Closed
 as Won't Fix Help for as Won't Fix


17
0
Sign in
to vote
Type: Suggestion
ID: 651185
Opened: 3/13/2011 2:03:48 PM
Access Restriction: Public
1
Workaround(s)
view

Description

The double.Parse method allows us to parse currency values:
var c = double.Parse("100.00$", NumberStyles.Currency, CultureInfo.CurrentCulture.NumberFormat);

This call takes care about the localization settings of the operating system. I would like the same feature for percent values. E.g.:

var p = double.Parse("100.00%", NumberStyles.Percent, CultureInfo.CurrentCulture.NumberFormat);

Lot solutions are found in the internet on how to parse percent values but most of them don't work right when the application is localized. Therefore, the .NET Framework should provide a correct solution in the BCL.
Details
Sign in to post a comment.
Posted by Marco Guignard on 4/24/2012 at 5:44 AM
I Agree. We have features for formatting with percent a number to string but nothing to parse it back !
Posted by Microsoft on 6/20/2011 at 9:50 AM
Thank you for the feature suggestions for NumberStyles and numeric parsing. We will record the request and number of up-votes and consider the change for the next major release of the .NET Framework.
Posted by ILa.MSDN on 6/17/2011 at 1:39 AM
Good idea ...and while you are at it, please also consider fractions of all available NumberStyles.
Posted by Andrea Antonangeli on 3/17/2011 at 11:10 AM
Agree. I was surprised not to find such an easy and common conversion
Posted by BlindSniper45 on 3/14/2011 at 7:17 AM
I agree. We can work with % sings in the visual studio IDE Why can't we parse them from strings ? It doesn't make sense.
Posted by Microsoft on 3/13/2011 at 7:11 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by Microsoft on 3/13/2011 at 7:11 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by Kevininstructor on 3/13/2011 at 6:02 PM
I believe that should be included too
Posted by dbasnett on 3/13/2011 at 4:46 PM
Decimal as well.
Posted by dbasnett on 3/13/2011 at 4:43 PM
I agree. I was surprised that Parse / TryParse didn't already.
Sign in to post a workaround.
Posted by TRANSACTSQL on 9/26/2012 at 10:07 AM
double nums = double.Parse(InterestRateTextBox.Text.Substring(0, InterestRateTextBox.Text.IndexOf('%'))) / 100D;
            mathieu_cupryk@hotmail.com

all exceptions should be delt with. This make .net look bad.