<div dir="ltr">I am parsing output from another system, where numbers arrive in a variety of forms which are out of my control. This one has caught me out recently:<div><br></div><div><p style="margin:0px;font-size:15px;font-family:Menlo;background-color:rgb(254,244,156)">1> binary_to_float(<<"2e-1">>).</p>
<p style="margin:0px;font-size:15px;font-family:Menlo;background-color:rgb(254,244,156)">** exception error: bad argument</p>
<p style="margin:0px;font-size:15px;font-family:Menlo;background-color:rgb(254,244,156)"> in function binary_to_float/1</p>
<p style="margin:0px;font-size:15px;font-family:Menlo;background-color:rgb(254,244,156)"> called as binary_to_float(<<"2e-1">>)</p></div><div><br></div><div><br></div><div>Whereas:</div><div><br></div><div><p style="margin:0px;font-size:15px;font-family:Menlo;background-color:rgb(254,244,156)">2> binary_to_float(<<"2.0e-1">>).</p>
<p style="margin:0px;font-size:15px;font-family:Menlo;background-color:rgb(254,244,156)">0.2</p></div><div><br></div><div><br></div><div>On:</div><div><br></div><div><p style="margin:0px;font-size:15px;font-family:Menlo;background-color:rgb(254,244,156)">erl -version</p>
<p style="margin:0px;font-size:15px;font-family:Menlo;background-color:rgb(254,244,156)">Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 6.3</p></div><div><br></div><div><br></div><div>Any good reason why in binary_to_float with a scientific notation the coefficient must be a float?</div><div><br></div><div>I'm now pattern matching this case before passing a modified coefficient as a floating point before passing it to binary_to_float.</div><div><br></div><div>Thanks,</div><div>Peter.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>