<div dir="ltr">Hi Sheng-Hung,<div><br></div><div>The underlying code simply does a cast in C to an integer (e.g. x = (int) y). The reason that you're seeing this behavior is that the number <span style="font-size:12.8px">2003201.942 has too many digits for a float (float only has ~7 digits), so you need to make this a double by adding the 'd' to the end. Unless you specify the 'd', NCL assumes a 4-byte float. </span><span style="font-size:12.8px">It seems like this should be happening for both examples, but that's a compiler/floating point implementation detail I guess.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">This should work they way you're expecting:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">print(toint(2003201.932d))</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">print(toint(2003201.942d))</span><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Hope this helps,</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Bill</span></div><div><span style="font-size:12.8px"><br></span></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>