Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: strange behavior of int() function...not truncating properly


From   Zachary Harrison <[email protected]>
To   [email protected]
Subject   st: strange behavior of int() function...not truncating properly
Date   Mon, 29 Jan 2007 14:25:12 -0800 (PST)

Hi all-

Here is a very simplified example demonstrating how
int() appears to not be properly truncating.  What am
I missing here?

. set obs 1
obs was 0, now 1

. gen v1 = 99.1400000

. format v1 %9.5f

. list

     +----------+
     |       v1 |
     |----------|
  1. | 99.14000 |
     +----------+

. gen v2 = int(v1 * 100)/100

. gen v3 = v1 * 100

. replace v3 = int(v3)
(0 real changes made)

. replace v3 = v3 / 100
(1 real change made)

. format v2 %9.5f

. format v3 %9.5f

. list

     +--------------------------------+
     |       v1         v2         v3 |
     |--------------------------------|
  1. | 99.14000   99.13000   99.14000 |
     +--------------------------------+

I realize I can do my truncation in more than 1 step,
as v3 does, but would like to know what is different
here.  I also of course realize the effect of
truncating 99.14 to 2 places is no change!

I am using Intercooled Stata 8.2 for Windows.

Thank you,

Zach


 
____________________________________________________________________________________
Don't get soaked.  Take a quick peak at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index