Forum Moderators: coopster

Message Too Old, No Replies

Outputting decimal places using PHP and Access

too many decimal places

         

djd4n

7:43 pm on Jun 2, 2005 (gmt 0)

10+ Year Member



I am storing prices in an MS Access database with the field that they are stored in set to currency, with 2 decimal places.

The prices are sent from a form using POST data. This is the put in the db via SQL.

When I come to retrieve the prices and show them on a PHP page they display wrongly e.g. 100.00 would show as 100.0000 or 134.50 would show as 134.5000.

They are correct in the actual db when viewed in Access, ie they have 2 decimal places.

I suppose I could strip the last two zeros off the string, but would like to get the bottom of it.

Any ideas anyone?

mcibor

7:51 pm on Jun 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There was such a topic here somewhere. Use number_format [php.net...]

<?php

$number = 1234.56;

// english notation (default)
$english_format_number = number_format($number);
// 1,234

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

$number = 1234.5678;

// english notation without thousands seperator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57

?>


hope this helps
Michal Cibor

mcavic

7:52 pm on Jun 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In PHP, try:

printf("%.2f", $value);