| Notices | Welcome to the Altnation forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |  | |
14th May 2008, 3:51pm
|
#1 | | (suicidemachine)
Join Date: Jan 2002 Location: Too large
Posts: 17,660
| How do I stop mysql rounding up? I am having a small issue with prices being rounded up when inserted into the db.
Product price is £22.07
It is stored in the products table as £22.07
When I display the price on a page it shows as £22.07.
When I process a transaction is appears into the db as £22.1
The value being inserted into the db is... Code: FormatNumber(item.PricePerUnit,2) How can I stop it being rounded up? |
| |
14th May 2008, 4:19pm
|
#2 | | Local Lolcat
Join Date: Jun 2004 Location: Tower Of High S
Posts: 2,976
| Re: How do I stop mysql rounding up? What's the datatype of the column?
__________________ ...To begin the New Dawn you can't live for 'her', 'him', 'me' or I', only Us. |
| |
14th May 2008, 5:06pm
|
#3 | | (suicidemachine)
Join Date: Jan 2002 Location: Too large
Posts: 17,660
| Re: How do I stop mysql rounding up? decimal |
| |
14th May 2008, 5:22pm
|
#4 | | STEVE HOLT!
Join Date: May 2001 Location: London
Posts: 5,958
| Re: How do I stop mysql rounding up? Where is FormatNumber from? Doesn't appear be a MySQL function.
What does 'processing' a transaction involve?
Also, post your full insert (or update) statement. |
| |
14th May 2008, 8:57pm
|
#5 | | Local Lolcat
Join Date: Jun 2004 Location: Tower Of High S
Posts: 2,976
| Re: How do I stop mysql rounding up? what's the precision of the decimal field? For a financial field it should be (18, 2) or have a precision of 4 to prevent rounding errors with VAT.
__________________ ...To begin the New Dawn you can't live for 'her', 'him', 'me' or I', only Us. |
| |
14th May 2008, 9:30pm
|
#6 | | (suicidemachine)
Join Date: Jan 2002 Location: Too large
Posts: 17,660
| Re: How do I stop mysql rounding up? i think its 19,4
I'll post more info when i get into work tomorrow |
| |
20th May 2008, 10:31am
|
#7 | | (suicidemachine)
Join Date: Jan 2002 Location: Too large
Posts: 17,660
| Re: How do I stop mysql rounding up? Quote:
Originally Posted by Zero Where is FormatNumber from? Doesn't appear be a MySQL function.
|
Completely forgot about this sorry, Format number is an asp function to determine how many decimal places to use.
Turns out that using 2 places was the problem.
I changed
FormatNumber(item.PricePerUnit,2) to
FormatNumber(item.PricePerUnit,3)
Cheers again! |
| |
20th May 2008, 11:55am
|
#8 | | STEVE HOLT!
Join Date: May 2001 Location: London
Posts: 5,958
| Re: How do I stop mysql rounding up? But why does that fix it? Looks like there is a deeper issue here. |
| |
20th May 2008, 12:40pm
|
#9 | | Local Lolcat
Join Date: Jun 2004 Location: Tower Of High S
Posts: 2,976
| Re: How do I stop mysql rounding up? FormatNumber looks like VBScript on the client side?
__________________ ...To begin the New Dawn you can't live for 'her', 'him', 'me' or I', only Us. |
| |
20th May 2008, 12:55pm
|
#10 | | (suicidemachine)
Join Date: Jan 2002 Location: Too large
Posts: 17,660
| Re: How do I stop mysql rounding up? Im not 100% sure why it is doing it, but I use the format number in my 'insert' statement... Code: strSQL = "INSERT INTO TRANSACTIONS_ITEMS(TransactionID,ProductName,Finish,Quantity,Price,ProductID,VAT,sectionCode) VALUES(" & _
transactionID & "," & _
"'" & AddSlashes(item.ProductName) & "'," & _
"'" & item.GetValue("Finish") & "'," & _
item.QuantityInBag & "," & _
FormatNumber(item.PricePerUnit,2) & "," & _
item.GetValue("PID") & "," & _
item.GetValue("VAT") & "," & _
"'" & item.GetValue("sectionCode") & "')" foirmat number,2 seems to set a price of £4.211 to £4.20 on insert and formatnumber,3 seems to set it to £4.21 |
| |
20th May 2008, 1:02pm
|
#11 | | Should Be Working
Join Date: Apr 2001 Location: Woodlands
Posts: 16,486
| Re: How do I stop mysql rounding up? that to me sounds like formatNumber is using significant figures rather than decimal places.
I'd check what it does to a price of £12.888
(rounding to three significant figures would give an end result after SQL insert of 12.90 I think, which is still wrong even if working for 4.211) |
| |
20th May 2008, 1:29pm
|
#12 | | STEVE HOLT!
Join Date: May 2001 Location: London
Posts: 5,958
| Re: How do I stop mysql rounding up? Log your strSQL, see what actually is before executing for both those cases. |
| |
20th May 2008, 2:26pm
|
#13 | | (suicidemachine)
Join Date: Jan 2002 Location: Too large
Posts: 17,660
| Re: How do I stop mysql rounding up? on a bit of a deadline so don't have time for testing at the moment.
Problem is solved, main thing.
Thanks again to all who offered help |
| |
20th May 2008, 2:30pm
|
#14 | | Registered User
Join Date: Jun 2001 Location: Aldgate East
Posts: 3,999
| Re: How do I stop mysql rounding up? Quote:
Originally Posted by Woolies that to me sounds like formatNumber is using significant figures rather than decimal places.
I'd check what it does to a price of £12.888
(rounding to three significant figures would give an end result after SQL insert of 12.90 I think, which is still wrong even if working for 4.211) | Quote:
Originally Posted by Largest of Gregs on a bit of a deadline so don't have time for testing at the moment.
Problem is solved, main thing.
Thanks again to all who offered help | Its not really solved until you have tested it with other cases... |
| |
20th May 2008, 3:19pm
|
#15 | | STEVE HOLT!
Join Date: May 2001 Location: London
Posts: 5,958
| Re: How do I stop mysql rounding up? |
| |  | | | Thread Tools | | | | Rate This Thread | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | |