I'm using a simple loop to echo back some numbers

```
<?php
$inc = 0.25;
$start = 0.25;
$stop = 5.00;
?>
<?php while($start != ($stop + $inc)){ ?>
<option><?php echo $start ?></option>
<?php $start = $start + $inc; ?>
<?php } ?>
```

However 5.00 appears as 5 and 4.50 appears as 4.5

How would i get this script to display 5.00, 4.00, 3.00, 3.50

Also apoligise for the title, i don't know how to explain this!

Thanks

use this:

```
echo sprintf("%01.2f", $start)
```

You'll want to use `printf()`

for formatted strings:

```
printf("%01.2f", $start)
```

The full manual for (s)printf can be found here

```
<?php while($start != ($stop + $inc)){ ?>
<option><?php printf('%01.2f', $start) ?></option>
<?php $start = $start + $inc; ?>
<?php } ?>
```

There also is number_format that lets you choose the thousand and decimal separators: http://de.php.net/manual/en/function.number-format.php

Check out the bcmath library.

Similar Questions

When converting a xls file to a csv file using 'Save as...' in Excel (which will then be imported into R), the csv output file systematically drops all numbers after the decimal point e.g. 1.0524 beco

How can i print the numbers of a float/double variable after the decimal point? For example: 435.5644 the output will be 5644 Thanks,

I want to extract numbers from a string in PHP like following : if the string = 'make1to6' i would like to extract the numeric character before and after the 'to' substring in the entire string. i.e.

I am using validation in GWT. I am having textbox. In that field it accepts only whole numbers and decimal values not other than special characters . I used regex pattern [0-9*] but it does not acce

In sublime text I have some data that contains numeric strings. Some are decimals and others are integers. I would like to remove the quotes to have them just as numbers. Is there a regular expression

How to round a decimal number to nearest 5 or nearest 10 in php

I have a simple function that I'm using but for some reason the number doesn't calculate correctly as it would in a calculator. I think it has something to do with the numbers being too large, or some

I read all rounding functions of T-SQL like Round,Floor,Ceil but none of them has round down decimal numbers correctly I have 2 questions: how to round down a decimal number? A value of 3.69 must sho

I need help for a starting point, really. We must use these 3 loops to generate a table of decimal numbers, as well as the binary, octal, and hexadecimal equivalents of the decimal numbers, in the ran

I want to format some numbers from my analytics into currency using the GB money format but as its for a dashboard and doesn't need to be that precise so I want to remove the pence (numbers after the

I have a series of CSV files where numbers are formatted in the european style using commas instead of decimal points, i.e. 0,5 instead of 0.5. There are too many of these files to edit them before im

I have a table with several columns, with DATA_TYPE FLOAT, NUMBER. There are whole numbers and decimal digits with decimal places. e.g. 234, 4, 0, 23.000000004, 234,4444, ... Assignment: I want that t

How can I add span with numbers after <h2>? Please see my code below: <pre> <?php $html=' <h2>hello</h2> <p>hello world</p> <h2>good</h2> <p>go

i am trying adding numbers like this $ctr = 0.0000001 + 0.0000001+ 0.0000001+ 0.0000001+ 0.0000001+ 0.0000001; echo floatval($ctr); it gives result like this 2.0E-5 i have tried, number_format, round

Interesting problem I have here, usually I just round up/down respectively for my needs with numbers but today I find myself having to be very specific. I am working on a project of which has many dot

PHP Code to add two numbers , adding happens as soon as i type the second number in the second field with the result populating in the third field. Can it be done using php or we do use Ajax or other

My program should convert decimal numbers to binary. For big numbers it is giving me a negative number not a binary number. Why is this? For example, if I supply 2321 I get 100100010001, which is fine

I want all of the elements in the array to be added together, but this doesn't seem to be working. <?php function mimic_array_sum($array) { foreach($array as $total) { $total = $total + $total; }

In PHP textfield: Prevent the user from entering more then 3 numbers before decimal point for example: if user enter 123.12 its acceptable, if user enter 12.12 its also acceptable, but if user enter 1

I have db with company id numbers and employers, now i need to know who is first, second ... employer entered in db. For this I need to add number for each one like this: CompanyID NameOfEmp PositionI

Lets say I have two numbers, Number 1: 1646 Number 2: 2089 You see adding them left to right without the carry on adds up to 3625 how would I do this in python? I'm not sure but I need it to add 9+6

Right Now I am making an app where the user is required to input a currency value, decimal point optional, into a UITextField. My problem comes up when I try to prevent more than 2 numbers after a giv

Ok. Basically I want to assign the numbers 1-3 to an infinite progression of numbers in PHP. How would I do this? I want to assign as follows. Core - 1. Supplement - 1. Core - 2. Supplement - 2. Core

The Twig documentation for number rounding talks about rounding decimals, but I have a case where I want to round a number like 19,995 to 20,000. Is there a tricky way to round up to nearest thousand?

I'm writings a PHP script that calculates an average of a number. EXAMPLE: $rating = 7; $votes = 3; $AvgRating = number_format($rating / $votes,1); The return $AvgRating for this would be 2.3 (to 1 d

is there anyway to add a group of decimal numbers and excel treat it as time? example; 15.00 = 15 hours 1.00 = 1 hour .20 = 20 minutes .45 = 45 minutes .15 = 15 minutes excel adds this to 16.80, but i

i try to add two numbers received from a file. But it shows only the last value of sum. Thx for the help! @FOR /F eol=; tokens=1-3 delims=, %%i IN (test.txt) DO ( set m=%%j set n=%%k set /a sum=%m%

I've been told this : Computers convert binary data into the hexadecimal (hex) number system because it is much less complex than converting data into decimal numbers. Why it is less complex?

What's the simple way to remove more than 1 decimal number from source number . for example source numbers are : 1st source number is : 56.48216585224 2nd source number is: 93 Output must be : 1st

Can you please help me to search the array for decimal numbers or part of it like . (dot and space after it) and replace it with zeros or remove the dot? Below is part of an array: Array ( [2] =>

Could any of you help me with a regex to allow this: 123.123 123. 1323.2 1.2312 1,23 123123,32 123, 123412 so to sum up: only one decimal point, it can be the last one.. but most not be the first. b

I have numbers (in decimal) I want to round it to nearest 50: 122 => round to 150 177 => round to 200 157 => round to 200 57 => round to 100; 37 => round to 50; 1557 => round t

This question already has an answer here: Is floating point math broken? 14 answers So I am making a script that adds two numbers (decimal numbers) together, which I have encountered a problem.

I need a R function that always returns same number of digits after the decimal point regardless of how big the argument is. I tried round() but it does not work this way. Here is my example: Rweb:&g

I want to convert double precision numbers to decimal . for example I have 23.43, the double value would be (using matlab) : 174 71 255 122 20 110 55 64 now having this how can I write a java program

exist any way to store in database a numbers with or without decimal point? The user can store to database numbers like 10 and 10.1 - for storing numbers in MySQL I use data type column decimal, so fo

I need to add 2 unsigned numbers 'a' and 'b' . I found the following Code , using bit operations unsigned int add (unsigned int a,unsigned int b) { unsigned int carry, sum; if (b == 0) { return a; } s

[I'm splitting a population number into different matrices and want to test my code using random numbers for now.] Quick question guys and thanks for your help in advance - If I use; 100*rand(9,1) W

I want to truncate numbers (given as strings) to a fixed number of decimal places. The numbers can be negative (with a minus sign), positive (no sign). I'd prefer to round the numbers properly and kee

is there framework way to know if there are numbers after point for printing. i want to show in textbox some decimal but if there is no numbers after the point the text should show int like that: txt.

This question already has an answer here: Format number to always show 2 decimal places 10 answers I have html table with numbers in cells (class numbers). Some numbers are whole numbers, oth

I am running into unexpected behaviour formatting very large numbers in ObjC using the NSNumberFormatter. It seems that the number formatter rounds decimals (NSDecimalNumber) after the fifteenth digit

This question already has an answer here: Truncate (not round off) decimal numbers in javascript 12 answers Im trying to get a number with precision to 2 decimals, for example this is what I wa

I'm trying to parse and add 2 numbers together where I don't know which type they are (int, float, etc.), and I'm trying to store the result in the most appropriate type. For instance, if I get 2 ints

how do I use decimal numbers with bigintegers? I would suspect the way I wrote, but obv it fails: @Test public void bigIntegerTestCalcs() { BigInteger a = new BigInteger(20); BigInteger b = new BigI

I'm working on localizing some strings in our application and we have text that looks something like: Factor f (1.0, 1.2, or 1.5) In a locale that uses a comma for the decimal point, would this be wr

I have this data: number 1 2 3 7.215115151215 2.5545158432 0 2 I would like it to be like this: number 1 2 3 7.21 2.55 0 2 I have tried to use number format and round 2 but it always changes things

Using JSONObject to read a json response from a server. The server returns some decimal number. Normal numbers are not a problem to but the problem occurs when there is decimal number of form 0.00068.

I am new to java dev. I want to add numbers in an editText. i.e if user types in 15 in editText, it should add the numbers 1 + 5 giving the result 6. Is there a function for it in java. In C# it is To

I am trying to add two decimal values but the returned sum is pure integer. What is wrong? I can't find it. any help will be welcome. jQuery(.delivery-method #ship_select).change(function(){ var cos