[erlang-questions] OtpErlangDouble/OtpErlangFloat
Martin Dimitrov
mrtndimitrov@REDACTED
Wed Aug 8 13:01:21 CEST 2012
Hello,
I have some strings in Java representing floating point numbers. I want
to transfer them to Erlang. So I create an object of type
OtpErlangFloat. The problem is that is rounds the number funnily. For
example,
String s = "22.4";
float f = Float.parseFloat(s);
System.out.println(f); // 22.4
OtpErlangFloat ef = new OtpErlangFloat(f);
System.out.println(ef.toString()); // 22.399999618530273
Then in Erlang:
mochinum:digits(Ef).
"22.399999618530273"
but
mochinum:digits(22.4).
"22.4"
Is there a way to keep the precision when constructing
OtpErlangDouble/OtpErlangFloat?
Thanks in advance,
Martin
More information about the erlang-questions
mailing list