Jump to content


Photo

Type cast a number to 3 digit float


  • Please log in to reply
4 replies to this topic

#1 Mateobus

Mateobus
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 11 September 2006 - 02:21 AM

I want to make a number have 3 decimal places regardless of what it is. Ie
$i = 7;

i want 7.00

#2 jefkin

jefkin
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 11 September 2006 - 03:56 AM

Um, what about 37  do you want 37.00 or 37.0  ???

Do you mean signifigant figures?

How about .00002323  do you want .000  or do you want .0000232

round()

provides some functionality you might find useful.

Jeff


#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 11 September 2006 - 08:44 AM

number_format() may also be of use.

#4 °°Ben³

°°Ben³
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationGermany / Remagen

Posted 11 September 2006 - 12:51 PM

sprintf(), too.
desktop and web development ;)
---
English is not my native language. Please excuse if I made some errors in expression.

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 11 September 2006 - 01:11 PM

number_format() may also be of use.


that's probably your best bet since it returns a float with the exact precision you request.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users