<div dir="ltr">The problem is floating point precision, which is only between 6 and 7 digits for decimal 32 bit floating point numbers. If you make your input value double precision you will obtain the correct values.<div>So you simply need to add 'd' to your input values:</div><br>ncl 1> print(toint(2003201.942)) <br>(0)     2003202<br>ncl 2> print(toint(2003201.942d))<br>(0)     2003201<div><br></div><div> -dave</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 1, 2018 at 8:29 AM, Sheng-Hung Wang <span dir="ltr"><<a href="mailto:wang.446@osu.edu" target="_blank">wang.446@osu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi<br>
<br>
How does function toint work?<br>
<br>
Here is my problem<br>
<br>
print(toint(2003201.932))<br>
<br>
print(toint(2003201.942))<br>
<br>
Accoring to NCL web page, toint should truncate any fractional part of vales, but I got 2003201 for 1st one, and 2003202 for 2nd one.<br>
<br>
I know I can replace toint to floor in this case. I just like to know what's really going on for the future.<br>
<br>
Thanks<br>
<br>
Sheng-Hung<br>
<br>
-- <br>
==============================<wbr>==========<br>
 Sheng-Hung Wang, PhD<br>
 Polar Meteorology Group<br>
 Byrd Polar and Climate Research Center<br>
 The Ohio State University<br>
 1090 Carmack Road, Columbus, Ohio 43210<br>
 Phone: <a href="tel:%28614%29%20292-1060" value="+16142921060" target="_blank">(614) 292-1060</a><br>
 Fax:   <a href="tel:%28614%29%20292-4697" value="+16142924697" target="_blank">(614) 292-4697</a><br>
 email: <a href="mailto:wang.446@osu.edu" target="_blank">wang.446@osu.edu</a><br>
==============================<wbr>==========<br>
<br>
______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailma<wbr>n/listinfo/ncl-talk</a><br>
</blockquote></div><br></div>