2

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?

XakAfrica
  • 39
  • 1
  • 5
  • 3
    http://php.net/manual/en/function.number-format.php ? – Peon Nov 20 '13 at 13:41
  • possible duplicate of [HTML5 Form Input Pattern Currency Format](http://stackoverflow.com/questions/5963158/html5-form-input-pattern-currency-format) – mplungjan Nov 20 '13 at 13:42

1 Answers1

8

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

baldrs
  • 2,132
  • 25
  • 34