I have textBox1 and it contains number 10. I need to get that number 10 to double with decimal point. My current code is:
variables.myNum = double.Parse(textBox1);
I have declared myNum in variables class:
public static double myNum;
With that code I get that number 10 to double. The problem is that I need to have decimal point too so I would like to have "10.". If I write to textBox1 "10." it doesn't work.
EDIT: .ToString("0.00") gives the decimal point to whole numbers but it also gives those two zeros which I do not want. Only point is needed with whole numbers.
EDIT: First I have:
10
10.5
10.58
10.589
I would like to have: (note dot after 1st ten)
10.
10.5
10.58
10.589
With .ToString("0.00") I can get:
10.00
10.50
10.58
10.58
But I don't want those extra zeros at the end. Only dot and numbers which are not zero.
You could just add a .
, if the output doesn't contain one already.
public static string ToGCodeNumber(double number, int digits)
{
// rounding (optional)
double number = Math.Round(number, digits);
// result with or without '.'
string intermediateResult = roundedNumber.ToString(CultureInfo.InvariantCulture);
if(!intermediateResult.Contains(".")
intermediateResult += ".";
// final result with a guaranteed '.'
return intermediateResult;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments