Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Decimal Rounding

Status
Not open for further replies.

nickdel

Programmer
May 11, 2006
367
GB
Having a problem rounding a number to the tenth decimal place. Using SAS V8.

Code:
data Inputs;
input NoIn $50.;
datalines;
325256.95299286436284664885258
;
run;

data Rounded;
	set Inputs;
	format NoOut 32.10;
	NoOut = round(NoIn,.0000000001);
run;

Would expect to see a return of 325256.9529928644 but instead getting 325256.9529928640.

It's not like it's complex code so don't really understand. Could this be a bug?

Thanks

Nick

where would we be without rhetorical questions...
 
SAS can't handle that degree of numerical accuracy in a numeric.
Run this instead and you'll see the correct decimal value...
Code:
data Inputs;
input NoIn $50.;
datalines;
256.95299286436284664885258
;
run;

data Rounded;
    set Inputs;
    put noin=;
    format NoOut 32.10;
    NoOut = round(NoIn,.0000000001);
    put noout=;
run;
The number is being rounded above and beyond what you've specified because it can't handle that many significant figures and decimal places.


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
This is an issue if you read a number this size in from a database too. Actually SAS seems to round it automatically which is bad! I use the CAST option to turn them to character fields because usually fields like this are ids, not real numbers.

SAS doesn't seem to have a workaround either. Strange for a product that touts itself as 'the power to know'.
 
I think that they work on the assumption that most people aren't going to need THAT many significant figures in their data. I mean, really, what on earth could you need all that for?
I remember at Uni (doing electronics engineering) seeing a lecturer cancel a Pi with a 3 because, with the size of the rest of the equation, the difference was pretty insignificant.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top