1

As the documentation states in Java's Float.toString(float) method, the float is represented with only as many digits that are needed to uniquely identify the value from adjacent float values. This behaviour isn't reflected in C#'s Single.ToString method.

This means that in Java:

1500.45504 produces 1500.4551
2000.37408 produces 2000.374

whereas in C#:

1500.45504 produces 1500.455
2000.37408 produces 2000.374

Am I missing a flag or something in C# to replicate Java's behaviour? I can only use floating points, so using more precision, like a double, isn't feasible in this situation. Also, I can't use the G<num>, or N<num> specifiers, because the output would vary depending on whether or not the output needs a unique digit identifier.

Nova
  • 31
  • 4
  • 3
    Seems like only a thing in .NET framework. .NET 5/6/7 produces 1500.4551 instead of 1500.455. In any case, [this might help](https://stackoverflow.com/questions/65478282/why-net-5-0-and-framework-in-c-sharp-does-not-return-same-value#comment116009860_65478282). (?) – Sweeper Jul 24 '23 at 02:30
  • @Sweeper is there any way that this can be manually implemented in v4.7.2? – Nova Jul 24 '23 at 07:19

0 Answers0