dickiebird
Programmer
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
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