-2
I would like to count how many characters there are after the comma. I was using
public static string strToDouble(String text)
{
string aux;
if (text.IndexOf(",00") <= 0)
{
aux = text + ",00";
return aux;
}
return text;
}
But it only returns me if these characters are in the variable.
I need to know if it has a comma and if so how many characters.
What you want to do exactly with the method
strToDouble()
? Take a number and if there are no decimal places add two?– João Martins
You need to clarify what you want, this method does one thing, you now want it to do something else? Or you want another method?
– Maniero
The idea of the method was to take the number if it had no decimal places and add yes.
– vinibsc
But I would like a method to count and I can add in a different way
– vinibsc
For example if the number is 1.5 it adds only a zero 1.50 if it is 1.06 it adds none if it is 1 it adds two zeros 1.00
– vinibsc
Let’s better understand what you want. Your method has a name that seems to want to transform a text to a number of the type
double
?. Is that correct? it seems to be an XY problem, you want something else from what you’re asking. Say what you need to solve to give the most appropriate solution, it seems that what you are asking is not the solution to your problem. What is the data you have? It’s a string being read somewhere?– Maniero