Wrox Programmer Forums Decimal place problem...ROUND function!
 | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersâ€™ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
June 30th, 2005, 07:36 AM
 Authorized User Join Date: Jun 2005 Location: , , . 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
Friend of Wrox
 Points: 4,332, Level: 27
 Activity: 0%

Join Date: Nov 2003
Location: , NJ, USA.
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
 Authorized User Join Date: Jun 2005 Location: , , . 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
Friend of Wrox
 Points: 4,332, Level: 27
 Activity: 0%

Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts

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

July 1st, 2005, 02:21 AM
 Authorized User Join Date: Jun 2005 Location: , , . 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
 Friend of Wrox Join Date: Jun 2003 Location: Bangalore, KA, India. 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
 Authorized User Join Date: Dec 2003 Location: , , . 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
Friend of Wrox
 Points: 4,332, Level: 27
 Activity: 0%

Join Date: Nov 2003
Location: , NJ, USA.
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
 Friend of Wrox Join Date: Jun 2003 Location: Bangalore, KA, India. 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
 Authorized User Join Date: Dec 2003 Location: , , . 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..

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is OffTrackbacks are Off Pingbacks are On Refbacks are Off Forum Rules

 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

All times are GMT -4. The time now is 08:37 PM.