Hi I am trying to assign values to numbers e.g. 01 instead of 1 like so:
$number = 01;
However PHP takes this to just be 1, how do I force it to keep the zero before it?
Zeros before numbers...
Moderator: General Moderators
treat it as a string
Code: Select all
$Var = '01';- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
You can always try using sprintf()
Here is a reverse example using currency:
Here is a reverse example using currency:
Code: Select all
<?php
$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
// echo $money will output "123.1";
$formatted = sprintf("%01.2f", $money);
// echo $formatted will output "123.10"
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK