Le Viet Hung
Le Viet Hung

Reputation: 529

Calculate some math, error "." instead of ","

I want to calculate some math in C#, but I have a problem. My numbers are all written with . instead of ,. For example 0.1 instead of 0,1.

(2^8 - 1)* 0.1 - 99.9

Because all of them are string, I convert them to int.

My code:

 String factor = "0.1";
 String offset = "99.9";

 Int64 result = (Convert.ToInt64(Math.Pow(2, 8) - 1) * Convert.ToInt64(factor.ToString().Replace(".", ","))) + Convert.ToInt64(offset.ToString().Replace(".", ","));

I am getting an error: "String not correct format."

Upvotes: 0

Views: 86

Answers (1)

L.B
L.B

Reputation: 116108

CultureInfo.InvariantCulture

var d = double.Parse("0.1",CultureInfo.InvariantCulture);

Upvotes: 5

Related Questions