Alternative Nation
Go Back   Alternative Nation > Lounge > Computers & Technology > Web Dev & Programming
Easy Wednesdays

Notices

Reply
 
Thread Tools Rate Thread
Old 14th May 2008, 3:51pm   #1
(suicidemachine)
 
Largest of Gregs's Avatar
 
Join Date: Jan 2002
Location: Too large
Posts: 17,660
Images: 1020
Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’
Send a message via MSN to Largest of Gregs Send a message via Skype™ to Largest of Gregs
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?
__________________
Like Siberia, remission is a silent journey across no man’s land, and it’s not always easy to take it alone.'
http://content.altnation.com/gallery.../6/dottsig.jpg
Largest of Gregs is offline   Reply With Quote
Old 14th May 2008, 4:19pm   #2
Local Lolcat
 
dalamarthedark's Avatar
 
Join Date: Jun 2004
Location: Tower Of High S
Posts: 2,976
Blog Entries: 16
Images: 19
dalamarthedark = 2nd Bestdalamarthedark = 2nd Bestdalamarthedark = 2nd Best
Send a message via MSN to dalamarthedark Send a message via Skype™ to dalamarthedark
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.
dalamarthedark is offline   Reply With Quote
Old 14th May 2008, 5:06pm   #3
(suicidemachine)
 
Largest of Gregs's Avatar
 
Join Date: Jan 2002
Location: Too large
Posts: 17,660
Images: 1020
Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’
Send a message via MSN to Largest of Gregs Send a message via Skype™ to Largest of Gregs
Re: How do I stop mysql rounding up?

decimal
__________________
Like Siberia, remission is a silent journey across no man’s land, and it’s not always easy to take it alone.'
http://content.altnation.com/gallery.../6/dottsig.jpg
Largest of Gregs is offline   Reply With Quote
Old 14th May 2008, 5:22pm   #4
STEVE HOLT!
 
Join Date: May 2001
Location: London
Posts: 5,958
Blog Entries: 1
Zero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to all
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.
Zero is offline   Reply With Quote
Old 14th May 2008, 8:57pm   #5
Local Lolcat
 
dalamarthedark's Avatar
 
Join Date: Jun 2004
Location: Tower Of High S
Posts: 2,976
Blog Entries: 16
Images: 19
dalamarthedark = 2nd Bestdalamarthedark = 2nd Bestdalamarthedark = 2nd Best
Send a message via MSN to dalamarthedark Send a message via Skype™ to dalamarthedark
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.
dalamarthedark is offline   Reply With Quote
Old 14th May 2008, 9:30pm   #6
(suicidemachine)
 
Largest of Gregs's Avatar
 
Join Date: Jan 2002
Location: Too large
Posts: 17,660
Images: 1020
Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’
Send a message via MSN to Largest of Gregs Send a message via Skype™ to Largest of Gregs
Re: How do I stop mysql rounding up?

i think its 19,4

I'll post more info when i get into work tomorrow
__________________
Like Siberia, remission is a silent journey across no man’s land, and it’s not always easy to take it alone.'
http://content.altnation.com/gallery.../6/dottsig.jpg
Largest of Gregs is offline   Reply With Quote
Old 20th May 2008, 10:31am   #7
(suicidemachine)
 
Largest of Gregs's Avatar
 
Join Date: Jan 2002
Location: Too large
Posts: 17,660
Images: 1020
Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’
Send a message via MSN to Largest of Gregs Send a message via Skype™ to Largest of Gregs
Re: How do I stop mysql rounding up?

Quote:
Originally Posted by Zero View Post
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!
__________________
Like Siberia, remission is a silent journey across no man’s land, and it’s not always easy to take it alone.'
http://content.altnation.com/gallery.../6/dottsig.jpg
Largest of Gregs is offline   Reply With Quote
Old 20th May 2008, 11:55am   #8
STEVE HOLT!
 
Join Date: May 2001
Location: London
Posts: 5,958
Blog Entries: 1
Zero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to all
Re: How do I stop mysql rounding up?

But why does that fix it? Looks like there is a deeper issue here.
Zero is offline   Reply With Quote
Old 20th May 2008, 12:40pm   #9
Local Lolcat
 
dalamarthedark's Avatar
 
Join Date: Jun 2004
Location: Tower Of High S
Posts: 2,976
Blog Entries: 16
Images: 19
dalamarthedark = 2nd Bestdalamarthedark = 2nd Bestdalamarthedark = 2nd Best
Send a message via MSN to dalamarthedark Send a message via Skype™ to dalamarthedark
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.
dalamarthedark is offline   Reply With Quote
Old 20th May 2008, 12:55pm   #10
(suicidemachine)
 
Largest of Gregs's Avatar
 
Join Date: Jan 2002
Location: Too large
Posts: 17,660
Images: 1020
Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’
Send a message via MSN to Largest of Gregs Send a message via Skype™ to Largest of Gregs
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
__________________
Like Siberia, remission is a silent journey across no man’s land, and it’s not always easy to take it alone.'
http://content.altnation.com/gallery.../6/dottsig.jpg
Largest of Gregs is offline   Reply With Quote
Old 20th May 2008, 1:02pm   #11
Should Be Working
 
Woolies's Avatar
 
Join Date: Apr 2001
Location: Woodlands
Posts: 16,486
Blog Entries: 89
Images: 1024
Woolies has all the rep they could need. And more.Woolies has all the rep they could need. And more.Woolies has all the rep they could need. And more.Woolies has all the rep they could need. And more.Woolies has all the rep they could need. And more.Woolies has all the rep they could need. And more.Woolies has all the rep they could need. And more.Woolies has all the rep they could need. And more.Woolies has all the rep they could need. And more.Woolies has all the rep they could need. And more.Woolies has all the rep they could need. And more.
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)
Woolies is offline   Reply With Quote
Old 20th May 2008, 1:29pm   #12
STEVE HOLT!
 
Join Date: May 2001
Location: London
Posts: 5,958
Blog Entries: 1
Zero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to all
Re: How do I stop mysql rounding up?

Log your strSQL, see what actually is before executing for both those cases.
Zero is offline   Reply With Quote
Old 20th May 2008, 2:26pm   #13
(suicidemachine)
 
Largest of Gregs's Avatar
 
Join Date: Jan 2002
Location: Too large
Posts: 17,660
Images: 1020
Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’Largest of Gregs is too good at this 'forum game’
Send a message via MSN to Largest of Gregs Send a message via Skype™ to Largest of Gregs
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
__________________
Like Siberia, remission is a silent journey across no man’s land, and it’s not always easy to take it alone.'
http://content.altnation.com/gallery.../6/dottsig.jpg
Largest of Gregs is offline   Reply With Quote
Old 20th May 2008, 2:30pm   #14
Registered User
 
m0nkeymafia's Avatar
 
Join Date: Jun 2001
Location: Aldgate East
Posts: 3,999
Blog Entries: 2
Images: 4
m0nkeymafia rawksm0nkeymafia rawksm0nkeymafia rawks
Send a message via MSN to m0nkeymafia
Re: How do I stop mysql rounding up?

Quote:
Originally Posted by Woolies View Post
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 View Post
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...
m0nkeymafia is online now   Reply With Quote
Old 20th May 2008, 3:19pm   #15
STEVE HOLT!
 
Join Date: May 2001
Location: London
Posts: 5,958
Blog Entries: 1
Zero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to allZero is a name known to all
Re: How do I stop mysql rounding up?

http://pragprog.com/the-pragmatic-pr...ts/coincidence
Zero is offline   Reply With Quote
Reply

Bookmarks
Digg del.icio.us StumbleUpon Google

Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Sin 



 Classic Grand Advert





Powered by vBadvanced CMPS v3.0.0
Advertisement
   



All times are GMT +0. The time now is 10:58pm.

Forums Directory
Copyright 2000-2008, Alternative Nation

SEO by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Page generated in 0.79124 seconds with 15 queries