Hello,

I am looking for a way to place an automatic . (dot) or , (comma) for every multiple of 3.

I only find the mask to do so but it requires the user to input the exact amount of numbers:

<script type="text/javascript">
$(function() {
  $.mask.definitions['~'] = "[+-]";
    $("#numbermask").mask("999,999,999",{completed:function(){alert("completed!");}});
    $("input").blur(function() {
    $("#info").html("Unmasked value: " + $(this).mask());
    }).dblclick(function() {
    $(this).unmask();
  });
});
</script>    

like the above code requires the user to enter (9 numbers) - I would like the user to be able to enter any number he wants and still automatically placing .(dot) for every multiple of 3.

Recommended Answers

All 5 Replies

I still do not understand how to use it:

Here is part of my codes:

Normally it works, without the number format (except for the dot for every multiple of 3) and normally I use integer for the data type. Now, I am using varchar.

add_package.php

<script>
function numberformat(num)
{
    result = num.toFixed(3);
    return result;
}
</script>

if (isset($_POST['ok'])){

        if (empty($_GET['package_id']))
            {
            $sqlstr = "INSERT INTO `package`(package_id, package, price) VALUES('".$package_id."','".$package."','".$price."')";            
            }
        else
        {   
            $fprice = numberformat($price);
            $sqlstr = "UPDATE `package` SET package='".$package."', price='".$fprice."' WHERE package_id=".$_GET['package_id'];         
        }

        $result = mysql_query($sqlstr) or die(mysql_error());

        //Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
        //if (empty($_REQUEST['id']))   kirimEmail($idKategori, $judul, $news);
        $confirmation = ($result) ? "Data has been saved." : "Fail to save dGagal menyimpan data."; 
    }

I receive this error message:

Fatal error: Call to undefined function numberformat() in C:\xampp\htdocs\administrator\admin\add_package.php on line 126

line 126: $fprice = numberformat($price);

I wonder how to fix the error?

It's number_format, not numberformat. These errors are the most basic errors in PHP. You should be able to read these no problem. You could've found this on Google VERY easily. Stop coming here just to get stuff easy. A little reading never does harm.

Don't take this in a negative way. The more you Google, the more you find out about PHP. The more errors you learn to read, the less you need help.
Oh, and line number is usually a massive hint, and "undefined function" is one, too.

Member Avatar for iamthwee

js parsely FTW!!

$fprice = number_format($price);
$sqlstr = "UPDATE `package` SET package='".$package."', price='".$fprice."' WHERE package_id=".$_GET['package_id'];
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.