Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String with negative float to float? [duplicate]

Tags:

c#

Here is basically the code I have :

string text = "-0.05537987";

float value = Single.Parse(text);

When I try and parse a negative number like I did here I get "Input string was not in the correct format."

like image 912
redonkulasman Avatar asked Jan 28 '26 05:01

redonkulasman


1 Answers

Your parsing should work, I believe your current culture has a different character for decimal separator. Use CultureInfo.InvariantCulture

float value = Single.Parse(text, CultureInfo.InvariantCulture);
like image 89
Habib Avatar answered Jan 29 '26 17:01

Habib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!