Nimesh
Nimesh

Reputation: 100

insert numerical data in appropriate format in textbox

When user insert amount in textbox at that time I want to insert amount in this format

100.00
1,000.00

How to i insert amount in this format in php periods and commas needs to be their in appropriate place.

Upvotes: 0

Views: 101

Answers (2)

Kaushik
Kaushik

Reputation: 2090

use number format of the variable like this

<?php
$number = strip_tags($_POST['number']);
echo number_format($number,2);

the second parameter in number_format() is upto which level you want a value. if you want upto 2 decimal places then it will be 2. if you want only integer the type cast it to int() this will help you . :-)

Upvotes: 0

Adam
Adam

Reputation: 1371

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

number format function

Upvotes: 1

Related Questions