If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MySQL Data type for percent

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-08-04, 04:33
lothario lothario is offline
Registered User
 
Join Date: Jan 2004
Posts: 6
MySQL Data type for percent

I am trying to set up 2 columns.
One is for Price in US dollars.
Two is for the percent markup (of the above Price).

Examples:
$100.00 for Price
10.5% for percent markup

So the resulting purchase price would be Price plus percent markup.
In this case it would be $110.50

I understand that DECIMAL 4,2 would be the approprate data type for the Price column.

What would be appropriate data type for the percent markup column?
Reply With Quote
  #2 (permalink)  
Old 05-08-04, 08:52
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Use decimal for that as well. You would write 10.5% as .105
you would need to use decimal (4,3) for that as you might need to represent a 100% or more markup.

Also you might find you need to use the round() function when doing your calculations to get the right number of decimals for your price.
Reply With Quote
  #3 (permalink)  
Old 05-08-04, 09:40
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
the largest number that decimal(4,2) can hold is 99.99

the largest number that decimal(4,3) can hold is 9.999
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 05-09-04, 01:22
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Well I was thinking that he would represent 10% as .1 and 100% as 1.00, the ,3 would be needed to represent the third digit of 1/2 percent as .005

Too many baseball stats for me I guess, since I'm used to representing a '300' batting average as .300

Last edited by guelphdad; 05-09-04 at 01:24.
Reply With Quote
  #5 (permalink)  
Old 05-09-04, 04:00
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
yeah, i realize that, dave, it's just that he said he wanted to represent his price as decimal(4,2), and i concluded that he assumed this was 4 digits left of the decimal point and two to the right, so i thought i would clarify for his sake

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On