Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse percentage to double

Is there a better way to parse percentage to double like this?

Dim Buffer As String = "50.00%"
Dim Value As Double = Double.Parse(Buffer.Replace("%",""), NumberStyles.Any, CultureInfo.InvariantCulture) / 100
like image 942
Dirk Brockhaus Avatar asked Jan 05 '10 09:01

Dirk Brockhaus


1 Answers

The way you are doing it seems good to me.

The only point I would be careful about is that your program is assuming InvariantCulture. Make sure this is actually what you mean. For example it might be better to use the machine's default culture if your string comes from user input rather than a fixed well-defined protocol.

like image 171
Mark Byers Avatar answered Nov 11 '22 12:11

Mark Byers