How to replace the comma

Asked

Viewed 3,861 times

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.

3 answers

8


  • but then the number won’t get "." ?

  • 1

    That’s what you asked for, change the comma for a point

  • +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 thanks, and I used double because it was already in the microsoft example and was not specified in the issue, but work with decimal.

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(',','.');

-2

When you use the ToString(CultureInfo.InvariantCulture), right after it is necessary to use the namespace

using System.Globalization;

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.