Jump to content


Photo

Mysql Float variables - 2 decimal places


  • Please log in to reply
3 replies to this topic

#1 gerkintrigg

gerkintrigg
  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 04 August 2006 - 01:15 PM

Hi. this is probably a very simple question, with a very simple answer, but it's baffling me...

Does anyone here know how to echo a MySQL float variable as two decimal places? Currently I'm using it to store prices in a database and whenever a cost if like £1.50p it only displays £1.5 which simply looks wrong.

Can anyone help please?

Thanks.
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 04 August 2006 - 01:44 PM

I know the round function works

round(5.2545, 2) would be 5.25

round(1.5,2) should in theory be 1.50
Tell me the problem, I will try tell you the solution

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 04 August 2006 - 01:46 PM

Also check out the number format and the money format functions

http://es2.php.net/m...mber-format.php

http://es2.php.net/m...oney-format.php
Tell me the problem, I will try tell you the solution

#4 gerkintrigg

gerkintrigg
  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 04 August 2006 - 03:04 PM

Eventually i used:
printf("%.2f", $total);

Thanks everyone.
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users