XakAfrica
XakAfrica

Reputation: 39

Number formatting for PHP generated text box

I have a simple PHP script helping me run a number calculator and the arithmetic part of it works fine, it draws input form the databse nicely.

<?php
$Userrate = $_POST['userrate'];
$Uservalue = $_POST['uservalue'];
$Usersolution = $Userrate * $Uservalue;

echo "<input name='Solution' style='width: 393px' type='text' value='$Usersolution' />"

?>

What I'm wondering is if I can apply a value to the generated text box to display the results in the [$MWK] #,##0.00 format. That is, so that instead of displaying 9000 as it does now, it displays MWK9,000.00

I've read its possible with Javascript but I'm trying to find an HTML application. Any help?

Upvotes: 2

Views: 2232

Answers (1)

baldrs
baldrs

Reputation: 2161

It is done with number_format function and some concatenation

echo $mvk.number_format($number, 2, '.', ',');

Note that last two arguments have . and , as a default values and can be omitted

http://php.net/manual/en/function.number-format.php

Upvotes: 8

Related Questions