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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I round a decimal to two pl

Status
Not open for further replies.

dickiebird

Programmer
Feb 14, 2002
758
GB
How can I round a decimal to two places ?
eg Column contains 45.9349340 but I want 45.93
I can do it in C :

1) Multiply the variable by 100
2) Add 0.5 to the variable
3) Cast it to an integer
4) Divide by 100
i.e.
computed_value*=100;
computed_value+=0.5;
int rounded_value=(int)computed_value;
computed_value=(double)rounded_value/100.0;

But how would I do it in SQL, specifically in an insert statement e.g :
insert
currency_detail
select
l.batch_number,
l.batch_position,
l.currency_code,
l.issuer_code,
NULL,
sum(((s.end_number - s.start_number)*s.denomination)/ exchange_rate)
from loader_table

Its the 'sum' line that results in figures to large decimal places.
Thanks in advance ;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Fixed it - I'd use round(sum(etc etc)/@exrate,2)
Doh ! Dickie Bird
db@dickiebird.freeserve.co.uk
 
There may me a round function available in your DBMS.

Ex: ORacle uses the following:

select round(25.2424,2) as rounded
from dual;

giving

rounded
-------
25.24

select round(25.2455,2) as rounded
from dual;

would give

rounded
-------
25.25

AA 8~)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top