Suppose i have the following,
r = RANDOMU(SEED,1)
and if the result is 0.423832.
How do i round it off to 0.42 ??
|
|
0
|
|
|
|
Reply
|
bala
|
4/21/2010 8:17:02 PM |
|
bala murugan writes:
> Suppose i have the following,
>
> r = RANDOMU(SEED,1)
>
> and if the result is Float(.
>
>
> How do i round it off to 0.42 ??
Print, Float(Long(r*100))
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
0
|
|
|
|
Reply
|
David
|
4/21/2010 8:49:27 PM
|
|
David Fanning writes:
> Print, Float(Long(r*100))
Whoops! You said "round it off".
Print, Float(Round(r*100))
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
0
|
|
|
|
Reply
|
David
|
4/21/2010 8:50:56 PM
|
|
On Apr 21, 3:50=A0pm, David Fanning <n...@dfanning.com> wrote:
> David Fanning writes:
> > Print, Float(Long(r*100))
>
> Whoops! You said "round it off".
>
> =A0 Print, Float(Round(r*100))
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
perhaps this will do it?
print, round(f*100.)/100.
|
|
0
|
|
|
|
Reply
|
Gianguido
|
4/21/2010 9:20:32 PM
|
|
David Fanning wrote:
> Print, Float(Round(r*100))
Maybe he also wants to divide by 100 again, to get to 0.42.
It should also be noted, that this method, or indeed anything that
involves rounding, does not work if the number to round does not fit
into a 32bit or 64bit integer (you will get an exception and the
result will be garbage). If that happens, you are probably trying to
round at a position waaaaay past the last significant digit anyway,
so the whole rounding step should be skipped. But you have to test for
it.
chl
|
|
0
|
|
|
|
Reply
|
Carsten
|
4/21/2010 9:39:01 PM
|
|
Gianguido Cianci writes:
> perhaps this will do it?
>
> print, round(f*100.)/100.
Oh, the hell with it. *Something* like that! ;-)
Cheers,
David
P.S. Why I try to answer a question when I have about
10 different things going on is a mystery to me!
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
0
|
|
|
|
Reply
|
David
|
4/21/2010 9:48:42 PM
|
|
Carsten Lechte writes:
> It should also be noted, that this method, or indeed anything that
> involves rounding, does not work if the number to round does not fit
> into a 32bit or 64bit integer (you will get an exception and the
> result will be garbage). If that happens, you are probably trying to
> round at a position waaaaay past the last significant digit anyway,
> so the whole rounding step should be skipped. But you have to test for
> it.
If you are looking for people with recent experience
to testify to how much trouble you can get into by
not testing data type bounds, I'm available at
my professional rate of $0.25/hour.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
0
|
|
|
|
Reply
|
David
|
4/21/2010 9:52:12 PM
|
|
bala murugan wrote:
> Suppose i have the following,
>
> r = RANDOMU(SEED,1)
>
> and if the result is 0.423832.
>
>
> How do i round it off to 0.42 ??
IDL> r = RANDOMU(SEED,1)
IDL> print, r
0.447645
IDL> print, r, format='(f4.2)'
0.45
I presume you meant "only print two digits after the decimal point" when you said "round
it off".
?
cheers,
paulv
|
|
0
|
|
|
|
Reply
|
Paul
|
4/22/2010 4:37:36 PM
|
|
On Apr 21, 4:17=A0pm, bala murugan <bala2...@gmail.com> wrote:
> Suppose i have the following,
>
> r =3D RANDOMU(SEED,1)
>
> and if the result is 0.423832.
>
> How do i round it off to 0.42 ??
When considering the all the answers given, it might be a good chance
to review the differences between ROUND, FLOOR, and CEIL.
try: print, round(r*100.)/100., floor(r*100.)/100., ceil(r*100.)/100.
|
|
0
|
|
|
|
Reply
|
Bob
|
4/22/2010 4:59:33 PM
|
|
|
8 Replies
750 Views
(page loaded in 3.325 seconds)
Similiar Articles: Rounding off - comp.lang.idl-pvwaveSuppose i have the following, r = RANDOMU(SEED,1) and if the result is 0.423832. How do i round it off to 0.42 ?? ... inch to millimeter in matlab - comp.soft-sys.matlabSuppose the input was a number that did not have round-off when represented in double precision -- i.e., an integer, or an integer divided by a power of 2 (up to 2^52). Algorithm behind "sum" command? - comp.soft-sys.matlabHi Matlab-ers, Does anybody know whether the "sum" command is implemented by any algorithm that is robust against round-off error? (e.g. the Kahan... Rounding numbers - comp.databases.filemakerRounding off - comp.lang.idl-pvwave It should also be noted, that this method, or indeed anything that involves rounding, does not work if the number to round does not fit ... PROC SQL and round-function - comp.soft-sys.sasSpecify round(var,.01) and you'll be much happier. From OnlineDocs: The ROUND function returns a value rounded to the nearest round-off unit. !P.Multi Broken in IDL 8.0.1 - comp.lang.idl-pvwaveRounding off - comp.lang.idl-pvwave > > > How do i round it off to 0.42 ?? IDL> r = RANDOMU(SEED,1) IDL> print, r 0.447645 IDL ... When rounding, you are finding the ... Cut a plane through 3D surface - comp.soft-sys.matlab... or whether to _check_ whether they are co-planar and decide > what to do if they are not (or suppose they are very very close and it > might plausibly be round-off ... [comp.publish.cdrom] CD-Recordable FAQ, Part 1/4 - comp.publish ...Archive-name: cdrom/cd-recordable/part1 Posting-Frequency: monthly Last-modified: 2008/10/09 Version: 2.71 Send corrections and updates to And... 2D FFT of images - comp.soft-sys.matlabRound-off error? How big are the imaginary parts compared to the conjugate? e.g., are they on the order of 10^(-14) times the maximum value of the conjugate (include ... addtodate bug? - comp.soft-sys.matlab... serial date number output by multiplying it by 86400000, performing a 'round' to ... newsreader/view_thread/307921 > > This problem may involve some kind of round-off ... Rounding Off Decimals - Office of Institutional Research and ...Objectives. After completing this unit, you should be able to: Determine whether a decimal should be rounded up or down. Round up decimals. Round down decimals. Rounding - Wikipedia, the free encyclopediaRounding a numerical value means replacing it by another value that is approximately ... Round-off error; Significant figures; Truncation; Signed zero; Signed-digit representation 7/25/2012 12:45:08 PM
|