double and float ToString("N0") formatting generates erroneous output (drops leading digit)
Target name(s)
ESP32_S3_ALL
Firmware version
1.12.4.187
Was working before? On which version?
No response
Device capabilities
No response
Description
double and float ToString("N0") and ToString("F0") produce erroneous output. It looks like the mscorlib Number.Format() rounds the value from 9.999 or 99.999 to 10 and 100 correctly, but when outputing the value, it does not output the leading 1.
How to reproduce
using System; using System.Diagnostics; using System.Threading;
namespace Blank { public class Program { public static void Main() { Debug.WriteLine("Hello from nanoFramework!");
double d = 9.8999;
Debug.WriteLine($"{d.ToString()}");
Debug.WriteLine($"{d.ToString("F")}");
Debug.WriteLine($"{d.ToString("F0")} F0 ERROR !");
Debug.WriteLine($"{d.ToString("N0")} N0 ERROR !");
Debug.WriteLine($"{d.ToString("N1")}");
d = 99.8999;
Debug.WriteLine($"{d.ToString()}");
Debug.WriteLine($"{d.ToString("F")}");
Debug.WriteLine($"{d.ToString("F0")} F0 ERROR !");
Debug.WriteLine($"{d.ToString("N0")} N0 ERROR !");
Debug.WriteLine($"{d.ToString("N1")}");
float f = 9.8999f;
Debug.WriteLine($"{f.ToString()}");
Debug.WriteLine($"{f.ToString("N")}");
Debug.WriteLine($"{f.ToString("N0")} ERROR !");
Debug.WriteLine($"{f.ToString("N1")}");
Debug.WriteLine($"{f.ToString()}");
Debug.WriteLine($"{f.ToString("F")}");
Debug.WriteLine($"{f.ToString("F0")} ERROR !");
Debug.WriteLine($"{f.ToString("F1")}");
f = 99.8999f;
Debug.WriteLine($"{f.ToString()}");
Debug.WriteLine($"{f.ToString("N")}");
Debug.WriteLine($"{f.ToString("N0")} ERROR !");
Debug.WriteLine($"{f.ToString("N1")}");
Debug.WriteLine($"{f.ToString()}");
Debug.WriteLine($"{f.ToString("F")}");
Debug.WriteLine($"{f.ToString("F0")} ERROR !");
Debug.WriteLine($"{f.ToString("F1")}");
Thread.Sleep(Timeout.Infinite);
}
}
}
Produces :
Hello from nanoFramework! 9.8999 9.90 0 F0 ERROR ! 0 N0 ERROR ! 9.9 99.8999 99.90 00 F0 ERROR ! 00 N0 ERROR ! 99.9 9.89990044 9.90 0 ERROR ! 9.9 9.89990044 9.90 0 ERROR ! 9.9 99.8999023 99.90 00 ERROR ! 99.9 99.8999023 99.90 00 ERROR ! 99.9
Expected behaviour
double d = 9.8999; Debug.WriteLine($"{d.ToString("F0")}"); Debug.WriteLine($"{d.ToString("N0")}");
Should produce : 10 10
instead of : 0 0
Screenshots
No response
Aditional information
No response