objeck / objeck-lang

Objeck is a modern object-oriented programming language with functional features tailored for machine learning. It emphasizes expression, simplicity, portability, and scalability. The programming environment consists of a compiler, virtual machine, REPL shell, and command line debugger with IDE plugins.
https://objeck.org
Other
154 stars 11 forks source link

How to use `System.IO.Standard->SetFloatFormat`? #458

Closed ghost closed 7 months ago

ghost commented 7 months ago

I'm currently using System.IO.Standard->SetFloatFormat(System.Number->Format->SCIENTIFIC);, but it doesn't work as expected.

I want it to print into the screen like this:

0.12345678912345

1.1234567891234e-08
objeck commented 7 months ago

Did you try?

System.IO.Standard->SetFloatFormat(Number->Format->SCIENTIFIC);
0.12345678912345->PrintLine();

Output: 1.234568e-01

ghost commented 7 months ago

You misunderstood me. I want to have more digits in the decimal part like this:

0.12345678912345

1.1234567891234e-08

This is how C#'s Console.WriteLine format the numbers by default.

I used the same code as you. And as you can see, the digits in the decimal part is too few: 1.234568e-01. I want it to display the same as C#.

objeck commented 7 months ago

I was unable to match the C# output exactly.

One can use the SetFloatPrecision(..) function to set precision; however, it is not guaranteed to decrement something like "e-1" to "e-2". The formatter may add another digit before "e-X" for example, "D.De-2" vs. "D.DDe-1". Underneath the hood, the runtime uses the C++ wstringstream class for formatting, which uses the same function as std::wcout.


value := 0.000004512345678912345;
String->SetFloatPrecision(2);
String->SetFloatFormat(Number->Format->SCIENTIFIC);
value->ToString()->PrintLine();
``