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

Trim Decimals in money datatype

Status
Not open for further replies.

essa2000

Programmer
Dec 6, 2000
299
0
0
CA
Dears ;

I want to trim more decimal places of the money and save data with two decimals in the database and for showing also.

For example :

If there are amount 47.7584, I want to save it as 47.75 without rounding it off.

I also want to use these values in calculations after trim .

immediate Help is required !

essa2000


 
Delcare a variable with decimal datatype having scale 2 and assign the original value to newly declared variable.

DECLARE @result decimal(5,2),
@value1 decimal(5,4), @value2 decimal(5,4)
SET @value1 = 1.1004
SET @value2 = 1.0004
SELECT @result = @value1
SELECT @result
select @result=@value2
select @result

Madhu.
 
Dear Madhu ;

I don't triming, but if we use these values then it also trims using your code ,

DECLARE @result decimal(5,2),
@value1 decimal(5,4), @value2 decimal(5,4)
SET @value1 = 1.1584
SET @value2 = 1.1874
SELECT @result = @value1
SELECT @result
select @result=@value2
select @result

I have found different solution and it works fine ,

IN SQL Server:
Floor function returns int part and this logic works fine

Select (floor(123.9987*100)/100)


In VB: in vb fix function does same ;

Debug.print fix(123.9987*100)/100)


Regards,
essa2000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top