0
I was wondering how can I replace the comma for a period.
Example: I have the following number 2.32 wanted it to be 2.32.
How can I do that?
I’ve tried using the ToString(CultureInfo.InvariantCulture)
but it still didn’t change.
0
I was wondering how can I replace the comma for a period.
Example: I have the following number 2.32 wanted it to be 2.32.
How can I do that?
I’ve tried using the ToString(CultureInfo.InvariantCulture)
but it still didn’t change.
8
You can do it like this:
double x = 2.32;
string texto = x.ToString("N", CultureInfo.CreateSpecificCulture("en-US"));
Reference: https://msdn.microsoft.com/en-us/library/d8ztz0sa(v=vs.110). aspx
1
You can use the method String.Replace(string1, string2)
or String.Replace(char1, char2)
, in 1 you put what you want to remove, and in 2 what you want to add, example:
string num = 2,32
num = num.Replace(',','.');
Browser other questions tagged c# floating-point
You are not signed in. Login or sign up in order to post.
but then the number won’t get "." ?
– Pedro Azevedo
That’s what you asked for, change the comma for a point
– Rovann Linhalis
+1 for not doing gambiarra. Only complementing that probably this number is a monetary value or something equivalent, and a
double
should not be used.– Maniero
@Maniero thanks, and I used
double
because it was already in the microsoft example and was not specified in the issue, but work withdecimal
.– Rovann Linhalis