Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own 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 support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > Displaying decimals correctly

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-23-02, 22:51
crighton crighton is offline
Registered User
 
Join Date: Feb 2002
Posts: 12
Displaying decimals correctly

Hi,

I'm in the thick of developing my first MySQL DB backed site and don't fully understand integer types and how they should be referred to in MySQL.

Prices on the site are currently all being rounded up (or down) but retaining two decimal points, eg. 12,00 or 123,00 when they should be 12,50 or 123,75 etc. (Note: comma is the decimal marker required.)

The field/s in question are currently set to Float(10,2). I've looked through the MySQL documentation but don't fully understand the differences between the integer types.

Can anyone shed any light?

Thanks in advance,

Gary Crighton
Reply With Quote
  #2 (permalink)  
Old 02-24-02, 11:58
Paul Paul is offline
Administrator
 
Join Date: Feb 2001
Location: NC, USA
Posts: 200
Are you sure it's not something in the app that's rounding? If you're using PHP, you may need to compile the bcmath options in.

The column types that should work are Decimal, Double and Float.
Reply With Quote
  #3 (permalink)  
Old 02-24-02, 12:40
crighton crighton is offline
Registered User
 
Join Date: Feb 2002
Posts: 12
Hi Paul,

I've been looking into this a little more but can still not identify where the error is occurring. I'm sure this is due to my inexperience with data types and numerals etc.

What I have noticed is this, the SQL data file is provided from the client with the prices inserted correctly, in this case in the format 123,50 etc. Once they are run through MySQL those numbers are rounded up/down and shown as 123,00 etc.

I've included sample code / data structure below in case there is some major booboo there.

Locally I'm using MySQLfront and did try to change the data type from float(10,2) to decimal(10,2) but this produced an error.

Someone has suggested that the problem lies with the format of the prices at import level - ie. 123,50 should be imported as 123.50 (hence it is ignoring everything after the comma), but if this is the numeral system here (Spain) obviously I can't ask the client to provide their prices in another format. If this is in fact the case is there some sort of workaround?

Any ideas?

Thanks in advance and all help / pointers appreciated!

Gary

PS. My First DB. I'll write the book from hell about it afterwards!

I'm using the following pieces of code -

Table structure:

CREATE TABLE productos (
Pedido varchar(7),
Titulo varchar(100),
ID int(4) unsigned,
Precio_Basico float(10,2),
Cuota_A float(10,2),
Cuota_B float(10,2),
Cuota_C float(10,2),
Year int(6) unsigned,
Formato_Obra varchar(60),
Formato_Papel varchar(60),
Tipo_Papel int(2) unsigned,
Tecnica varchar(100),
Descripcion_es text,
Descripcion_en text
) TYPE=MyISAM;

Sample row:

INSERT INTO productos VALUES("10272","El criticón","306","89,55","85,07","80,6","71,64","", "","","","","","");

To display the prices:

Spanish format <?PHP echo number_format($row["Cuota_A"], 2, ',', '.'); ?>
UK / US format <?PHP echo $row["Cuota_A"] ?>
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

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