Wrox Programmer Forums Decimal place problem...ROUND function!
 |
 SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
 Welcome to the p2p.wrox.com Forums. You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

June 30th, 2005, 07:36 AM
 kuku Authorized User Join Date: Jun 2005 Posts: 21 Thanks: 0 Thanked 0 Times in 0 Posts
Decimal place problem...ROUND function!

Hi everyone,
i have another problem, hope someone can help me!
i have a ROUND function like this..
ROUND(amount, 4)
This function will round up to 4 digit decimal place if the amount more than 4 digit decimal place, e.g 4.56879 -> 4.5688
But if the amount less then 4 digit decimal place, e.g 4.23 -> 4.23. it will display the same amount.
My question is, how i can add the zero at the back, make up like 4.2300, because i want all the amount will have 4 digit decimal place when it display in the screen.
what i can add to the ROUND function??????
Thanks!

June 30th, 2005, 12:48 PM
 jbenson001 Friend of Wrox Join Date: Nov 2003 Posts: 1,348 Thanks: 0 Thanked 5 Times in 5 Posts

how is your amount column defined? I tried using a decimal(7,4)-- total of 7 places with 4 after the decimal. This will produce the results you want

June 30th, 2005, 05:44 PM
 kuku Authorized User Join Date: Jun 2005 Posts: 21 Thanks: 0 Thanked 0 Times in 0 Posts

The problem is all the tables in the system is already pre-define, so i cant change the table structure.
Is there any other solution can solve the problem?

July 1st, 2005, 01:13 AM
 jbenson001 Friend of Wrox Join Date: Nov 2003 Posts: 1,348 Thanks: 0 Thanked 5 Times in 5 Posts

Try Select(convert(decimal(7,4), amount)

July 1st, 2005, 02:21 AM
 kuku Authorized User Join Date: Jun 2005 Posts: 21 Thanks: 0 Thanked 0 Times in 0 Posts

But my pre-defined data type is FLOAT, and i try the COVERT function with that, it doesn't work!!!
Any other solution?

July 6th, 2005, 04:31 PM
 happygv Friend of Wrox Join Date: Jun 2003 Posts: 2,480 Thanks: 0 Thanked 1 Time in 1 Post

So what is the output you see when trying jbenson's suggestion?

_________________________
- Vijay G
Strive for Perfection

July 8th, 2005, 11:34 AM
 Pavesa Authorized User Join Date: Dec 2003 Posts: 38 Thanks: 0 Thanked 0 Times in 0 Posts

Have you tried Format? In the form:

Format(MyVar, "0.###############")

should display that number of decimals even if it is rounded?

July 8th, 2005, 12:17 PM
 jbenson001 Friend of Wrox Join Date: Nov 2003 Posts: 1,348 Thanks: 0 Thanked 5 Times in 5 Posts

What is Format()? This is not a SQL function.

July 8th, 2005, 05:45 PM
 happygv Friend of Wrox Join Date: Jun 2003 Posts: 2,480 Thanks: 0 Thanked 1 Time in 1 Post

Pavesa,

Format is not an SQL function, all that discussed here are pertaining to SQL function. This is a SQL server forum. Hope you have posted VB/VBscript function here by mistake.

_________________________
- Vijay G
Strive for Perfection

July 9th, 2005, 05:50 PM
 Pavesa Authorized User Join Date: Dec 2003 Posts: 38 Thanks: 0 Thanked 0 Times in 0 Posts

Hi Vijay,

sure it was a mistake, I didn't spend long enough thinking about the guy's problem. As your motto is "strive for perfection", maybe your "perfection" leads you to know perfectly why the Evaluation version of SQL server won't install on my computer? See my posting yesterday..

 Similar Threads Thread Thread Starter Forum Replies Last Post Round up up to 2 decimal pt in crysatl Report prafullaborade VB How-To 0 September 26th, 2008 04:59 AM regular expression for number upto 2 decimal place swati_joshi ASP.NET 1.0 and 1.1 Basics 3 July 31st, 2008 11:23 AM Problem with Round Function darrenb Access 3 May 22nd, 2007 05:45 PM round up a decimal number semooth VB How-To 3 October 4th, 2005 02:33 PM Round to 2 decimal places adman JSP Basics 0 June 30th, 2005 07:24 AM