-1

hai

i want to convert interger number to float number, how in php?

for ex
i want to convert 500 to 500.00

6
Contributors
8
Replies
11
Views
8 Years
Discussion Span
Last Post by applemist
0

i want to just display the 500 to 500.00 in webpage. how can i achieve with php

For example
name cost
item1 500.00
item2 350.00

0

Just store the numbers with the decimal value, if they are in a MySQL database there is a DECIMAL datatype for this, in MSSQL there is a CURRENCY one. If the values are hard-coded into the scripts, just add .00 to the end of them.

If I am missing the point please provide a code example as you are giving little to go by on what you want.

0

i want to convert interger number to float number, how this is possible in php? for example i want to convert 500 to 500.00

Edited by happygeek: fixed formatting

0

Just store the numbers with the decimal value, if they are in a MySQL database there is a DECIMAL datatype for this, in MSSQL there is a CURRENCY one. If the values are hard-coded into the scripts, just add .00 to the end of them.

If I am missing the point please provide a code example as you are giving little to go by on what you want.

Excellent!, Thanks for that Decimal datatype, i was breaking my head with float datatype for a long time..

0

All are variables are automaticalled assigned dataype relevant to your value. if your give 500 default is string, you can convert it to decimal using double or float. but the output should be the same. use sprintf to achieve the solution like below

<?php
$value='500';
echo "<b>Default datatype:</b> " . gettype($value) . "<br/>";

settype($value,"double");
echo "<b>After conversion:</b> " . gettype($value) . "<br/>";

print "Way to use decimal in output ".sprintf("%4.2f", $value);

?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.