Jump to content

[SOLVED] number formatting


nitation

Recommended Posts

Hello,

 

I just want to know how to format an amount value in my database to have commas.

 

example;

 

the value i entered is 45000, how do i  format it to be like this; 45,000 and when i deduct, it will deduct correctly. Cos when am trying it, it will only deduct the FIGURES before the comma sign.

 

Thanks in advance.

Link to comment
Share on other sites

If none of your numbers contain a comma, subtraction works fine. Also, if you try to store a number with a comma into a field of type "int" it won't work. If you already have your number stored with commas, I would suggest you modify those stored numbers to get rid of the commas.

 

Ken

Link to comment
Share on other sites

Yes, never store numbers in the database that have commas in them.

 

As for data which is entered in a form, just use the str_replace() function to remove the commas:

<?php
$data = str_replace(',',$_POST['data']);
?>

 

Ken

Link to comment
Share on other sites

@ken

 

I posted the code you gave me on line 29 of my code. this is what i get

 

Warning: Wrong parameter count for str_replace() in C:\Program Files\xampp\htdocs\myfiles\vest\canada\internets\transfer.php on line 29

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.