Home » SQL & PL/SQL » SQL & PL/SQL » to get the round off value of a float value
to get the round off value of a float value [message #228580] Tue, 03 April 2007 07:28 Go to next message
cutsmartprem
Messages: 62
Registered: November 2006
Member
Hi,
I want the correct round off value of the float value for a specific number of decimal places. The functions of ceil and floor cant be used in this case.
Is there any built in function to get the round off value of a float value.
Request you to help me out.
Re: to get the round off value of a float value [message #228584 is a reply to message #228580] Tue, 03 April 2007 07:33 Go to previous messageGo to next message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
Have you never heard of ROUND function?
edit:
select round(99.25346,2) from dual;
--99.25
select round(99.25546,2) from dual;
--99.26
By
Vamsi

[Updated on: Tue, 03 April 2007 07:36]

Report message to a moderator

Re: to get the round off value of a float value [message #228585 is a reply to message #228584] Tue, 03 April 2007 07:34 Go to previous messageGo to next message
cutsmartprem
Messages: 62
Registered: November 2006
Member
ya thanks...
Re: to get the round off value of a float value [message #228596 is a reply to message #228580] Tue, 03 April 2007 07:59 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
The functions CEIL and FLOOR most certainly CAN be used in this case.
SELECT FLOOR((99.234567*POWER(10,3))+0.5)/POWER(10,3) FROM dual;

FLOOR((99.234567*POWER(10,3))+0.5)/POWER(10,3)
99.235


IN general:
SELECT FLOOR((n*POWER(10,x))+0.5)/POWER(10,x) FROM dual;
or
SELECT CEIL((n*POWER(10,x))-0.5)/POWER(10,x) FROM dual;

Where n is the number to round, and x is the number of decimal places to round to.

You'd need locking up if you actually used this when ROUND is available, but I took the OP as a bit of a challenge.
Previous Topic: Display results in one query with different WHERE conditions
Next Topic: temporary tables problem
Goto Forum:
  


Current Time: Sun Dec 11 04:27:21 CST 2016

Total time taken to generate the page: 0.09999 seconds