Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: how to keep number after comma only
From
Sergiy Radyakin <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: how to keep number after comma only
Date
Tue, 25 Feb 2014 11:53:39 -0500
. local x=-3.1415
. di mod(`x',1)
.8585
. di `x'-floor(`x')
.8585
Though this is not your case, probably. But I would still put an
'assert (term>=0)' before getting the fraction in a way like this.
Also note that Stata defines mod(x,y) as x - y*int(x/y) on domain (-inf;+inf).
I don't think it is working for negatives:
. di mod(`x',1)
.8585
. di mod(`x',2)
.8585
Best, Sergiy
On Tue, Feb 25, 2014 at 11:36 AM, Nick Cox <[email protected]> wrote:
> The fractional part is the remainder on division by 1.
>
> . di mod(_pi, 1)
> .14159265
>
> . di mod(3.1,1)
> .1
>
> or the difference between a number and its floor.
>
> Nick
> [email protected]
>
>
> On 25 February 2014 16:24, Dao Kim <[email protected]> wrote:
>
>
> I am trying to keep only the digits of a number, for example 37.1
> weeks in order to convert it into days. I could keep the first 2
> numbers with "gen long term_days = floor(term/10)", how does it work
> for the number after the comma?
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/