hai

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

for ex
i want to convert 500 to 500.00

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

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.

i want to convert 500 to 500.00

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

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..

Member Avatar for rajarajan2017

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);

?>

Thanks! it helps me a lot! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.