Prev: Help in Macro needed
Next: Plese help: Urgent: compare columns in 2 tables based on value from third table
From: vncntj on 17 Apr 2010 07:38 I have: length = 0.20 + 0.05 * ranuni(0); but I'm trying to limit the value to 2 decimal places instead of 0.2499872231 trimmed to 0.24 Thanks
From: Barry Schwarz on 17 Apr 2010 14:16 For n decimal places, multiply by 10^n, take the integer portion of the answer, and then divide by 10^n. Of course, you are aware that values like .24 can never be represented exactly in binary (just as 1/3 can never be represented exactly in decimal). But the approximation used by SAS will be much closer than ..24998... On Sat, 17 Apr 2010 04:38:17 -0700 (PDT), vncntj <vincent.s.jones(a)gmail.com> wrote: >I have: > > length = 0.20 + 0.05 * ranuni(0); > >but I'm trying to limit the value to 2 decimal places instead of > >0.2499872231 > >trimmed to > >0.24 > >Thanks -- Remove del for email
From: Tom Abernathy on 17 Apr 2010 20:11 On Apr 17, 7:38 am, vncntj <vincent.s.jo...(a)gmail.com> wrote: > I have: > > length = 0.20 + 0.05 * ranuni(0); > > but I'm trying to limit the value to 2 decimal places instead of > > 0.2499872231 > > trimmed to > > 0.24 > > Thanks Are you looking for the ROUND function? To round to the nearest hundredth you would do this: length=round(length,0.01);
From: Patrick on 18 Apr 2010 00:37 Hi The following gives you random numbers with 2 decimals between 0.20 and 0.25: length=0.20 + ceil(ranuni(0)*5)/100; HTH Patrick
From: Patrick on 18 Apr 2010 00:42
Ooops! Forgot about 0. That's the correct code: length=0.20 + floor(ranuni(0)*6)/100; |