Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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
 
Old August 7th, 2004, 09:01 PM
Authorized User
 
Join Date: Jun 2004
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default Not sure-- Sqlserver? ASP.NET?

Guys, this is a simple question for you able programmers.
I have 4 decimal data type variables in my asp.net page:
amount, tax, shipping, total.
what is happening is that when tax is calculated as (amount * 6/100) and if the amount is 4.25, it calculates tax = .255 and if the shipping amount chosen was 2.50, the total amount comes to 7.005.

What I would like to be able to do is limit the tax result to 2 digits after the decimal so that .255 is .26 and 7.005 is 7.01. In fact .26 and 7.01 are what is displayed in my asp.net page as I have applied string formatting {0:c}. The trouble is in the database, .26 is stored as .255 and 7.01 as 7.005 and these values get passed on to my order processor that deems 7.005 as "invalid amount".

The database columns storing these values are of type money, 8. Is there any way I can manipulate the precision or scale of the values stored in these columns programmatically when they are calculated in the asp.net page? Thanks. Much appreciated -- I have learned a lot in this forum.

 
Old August 7th, 2004, 09:55 PM
Authorized User
 
Join Date: Jun 2004
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I will try the decimal.Round method. Hopefully, it will work. Let me know if you have any other ideas.

 
Old August 7th, 2004, 10:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Shailesh,

You cannot alter Money datatype for to have only 2 digits after decimal. Instead you can use decimal datatype there - decimal(n,2)

OR
Code:
select cast(7.005 as decimal(5,2))
But, if you are specific about using money datatype there, you got to convert it when you retrieve it from the database.

Code:
DECLARE    @myVar money
SELECT    @myVar = 7.005
SELECT    CONVERT(varchar(10), @myVar, 1)
OR
Code:
SELECT CONVERT(varchar(10), MoneyColumn, 1) from YourTable
Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old August 9th, 2004, 02:37 PM
Authorized User
 
Join Date: Jun 2004
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Vijay:

Thanks for replying. In fact, the decimal.Round method seems to be working. I calculate tax first like tax = amount * 6/100 and then round off the result in the next line as tax = decimal.Round(tax, 2). so if in the first line tax is 2.555, the next line make it 2.6 and then inserts it as such in the database. I am using the same method in the amount calculation as well & it seems to be working -- basically, I just round it off before I make the call to store it in the database.

Thanks again for replying. It is all working now -- much appreciated.
Shailesh.


 
Old July 7th, 2006, 10:52 AM
Registered User
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Decimal.Round() seems to have changed in .Net 2.0. The second parameter is no longer a specification of decimal places but an enumeration specifying how it will round to an integer. The MSDN documentation (http://msdn2.microsoft.com/en-us/lib...l_members.aspx) on the function states that the function is new in .net 2.0. So you should use System.Math.Round() to round your decimal values.

 
Old August 9th, 2006, 08:33 AM
Registered User
 
Join Date: Aug 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ihave a display screen consisting of values ie : 93 that are not in decimals.
but when we wish to edit the button we find the values in decimal ie : 93.10
when we save the data value saved in database is in decimal ie: 93.10.

But the problem is.....

 1...i want the value as 93 when edited.
 2... i want the value stored in database as 93.10

here when the value is rounded from 93.10 to 93 the data is changed in database...

will u please solve me this problemmm...its very urgent.

in asp


bonny





Similar Threads
Thread Thread Starter Forum Replies Last Post
sending email from asp.net/sqlserver on a particul hepsy.i ASP.NET 1.0 and 1.1 Professional 1 July 11th, 2008 08:09 AM
SQLserver 2000 vs SQLserver 2005 Express cJeffreywang BOOK: Beginning ASP.NET 2.0 and Databases 0 April 22nd, 2007 09:52 AM
Upgrading ASP w/ SQLserver 2000 to ASP.NET w/2005 cJeffreywang ASP.NET 2.0 Basics 1 April 5th, 2007 11:30 PM
problem with asp+sqlserver thiagoserra Classic ASP Databases 0 July 11th, 2003 10:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.