Board index » delphi » truncate after 2 decimal point

truncate after 2 decimal point


2003-12-16 10:34:05 PM
delphi51
How can i do this
190.56789 I would like to truncate 190.56 instead 190.57
Thanks
 
 

Re:truncate after 2 decimal point

yes in db, i use sql server 2000
thanks
Ross <XXXX@XXXXX.COM>writes:
Quote
ganesh writes:
>How can i do this
>
>190.56789 I would like to truncate 190.56 instead 190.57
>
>Thanks
Depends on the database. Which are you using? Assuming you want to do
this on the DB side...

Ross

 

Re:truncate after 2 decimal point

ganesh writes:
Quote
How can i do this

190.56789 I would like to truncate 190.56 instead 190.57

Thanks
Depends on the database. Which are you using? Assuming you want to do
this on the DB side...
Ross
 

Re:truncate after 2 decimal point

it's not true always
pls look at this
declare @testFloat float
select @testFloat = 1307.33
select @testFloat = Floor(@testFloat*100)/100
select @testFloat
the out put is
1307.3299999999999
Thanks
"Guillermo Castaņo A" <XXXX@XXXXX.COM>writes:
Quote
FLOOR(YourValue * 100) / 100

--
Guillermo Castaņo A.
www.GrupoMillennium.com
"ganesh" <XXXX@XXXXX.COM>writes
news:3fdf278e$XXXX@XXXXX.COM...
>
>yes in db, i use sql server 2000
>
>thanks
>
>Ross <XXXX@XXXXX.COM>writes:
>>ganesh writes:
>>>How can i do this
>>>
>>>190.56789 I would like to truncate 190.56 instead 190.57
>>>
>>>Thanks
>>Depends on the database. Which are you using? Assuming you want to do
>>this on the DB side...
>>
>>Ross
>>
>


 

Re:truncate after 2 decimal point

ganesh writes:
Quote
the out put is

1307.3299999999999
That's why floating-point numbers suck. Convert it to money first.
--
Cheers,
Ignacio
 

Re:truncate after 2 decimal point

FLOOR(YourValue * 100) / 100
--
Guillermo Castaņo A.
www.GrupoMillennium.com
"ganesh" <XXXX@XXXXX.COM>writes
Quote

yes in db, i use sql server 2000

thanks

Ross <XXXX@XXXXX.COM>writes:
>ganesh writes:
>>How can i do this
>>
>>190.56789 I would like to truncate 190.56 instead 190.57
>>
>>Thanks
>Depends on the database. Which are you using? Assuming you want to do
>this on the DB side...
>
>Ross
>

 

Re:truncate after 2 decimal point

The odd thing... rounding the result to two decimals neither worked
ROUND(@TestFloat,2) still returns 1307.3299999999999.
But rounding to one decimal return 1307.3
--
Guillermo Castaņo A.
www.GrupoMillennium.com
"ganesh" <XXXX@XXXXX.COM>writes
Quote

it's not true always

pls look at this

declare @testFloat float
select @testFloat = 1307.33

select @testFloat = Floor(@testFloat*100)/100
select @testFloat


the out put is

1307.3299999999999


Thanks

"Guillermo Castaņo A" <XXXX@XXXXX.COM>writes:
>FLOOR(YourValue * 100) / 100
>
>--
>Guillermo Castaņo A.
>www.GrupoMillennium.com
>"ganesh" <XXXX@XXXXX.COM>writes
>news:3fdf278e$XXXX@XXXXX.COM...
>>
>>yes in db, i use sql server 2000
>>
>>thanks
>>
>>Ross <XXXX@XXXXX.COM>writes:
>>>ganesh writes:
>>>>How can i do this
>>>>
>>>>190.56789 I would like to truncate 190.56 instead 190.57
>>>>
>>>>Thanks
>>>Depends on the database. Which are you using? Assuming you want to do
>>>this on the DB side...
>>>
>>>Ross
>>>
>>
>
>

 

Re:truncate after 2 decimal point

Use Round
try this
select Round(123.4556,2,1)
it returns 123.4500
You could do some formatting to get just 123.45
The third argument in the round expression is the key. The "function"
parameter determines if the value is truncated or rounded. If the value
is not equal to 0 then it will truncate the value. Read about round in BOL.
Ross