This question already has answers here:
Add comma to numbers every three digits
(14 answers)
How to format numbers? [duplicate]
(17 answers)
Closed 8 years ago.
Hello there i have problem in jQuery. Suppose i have a value like 20000. And i want the value like 20,000 that after two number a comma will be inserted. I can't do it using jQuery. Please anyone help me out.
Since you said you want the comman inserted "after two numbers", I'm going to assume you have the easy case where you know that your input is a 5 digit number and don't want a more generic number formatting solution. In that case you can do something just like:
var num = 20000;
num = num.toString();
num = num.substr(0,2) + ',' + num.substr(2);
// Now num === "20,000"
Note that 20,000 will only read as twenty-thousand in certain locales. It could be read as just twenty in many locales, but 20000 will be read correctly by anyone who understands Arabic numerals.
Related
This question already has answers here:
Getting a number when it has certain prefix from a block of text in PHP
(3 answers)
Zero-pad digits in string
(5 answers)
Closed 1 year ago.
I am trying to add the int with strings in PHP but I could get a helpful answer on StackOverflow and other website communities.
I want the code separate the ALPHABETS and NUMBER and then add the value in NUMBER and again JOIN the ALPHABETS AND ADDED NUMBER together.
How I achieve this, Please help.
Example:
$mynumber = 'SBI0001';
$addValue = '1';
It will be 'SBI0002' in PHP.
This question already has answers here:
Is storing a delimited list in a database column really that bad?
(10 answers)
Closed 2 years ago.
One of my column value is like 50-17-140(This value is showing the size details for the eyeglasses).
This is unique for every product. So this 50 can be 45 to 60 and so on.
Is it possible to fetch these numbers(50, 17, 140) separately in PHP?
What will be code if I want to show only 50 somewhere of only 17 etc.
Simple - use explode:
$value = '50-17-140';
$chunks = explode('-', $value);
$size = $chunks[0];
echo $size;
But in fact you should really think about cleaning up your database. This composed string, which is obviously stored in a single database field, should be split into three separate fields.
Let's say you want to fetch all records having 140 as the third value. If this is properly stored in a column, you will be able to just query for it.
This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 5 years ago.
I'm currently working on retrieving data from coinmarketcap API and I would like to limit the strings to 5. I retrieve the data and then multiply the value *1.07 and the result to MXN, but the string is long, like 25.65675734343, I want to limit that string, this is my echo:
echo $xrpprice*$rate*$fxrates['rates']['MXN'];
Use round:
$result = $xrpprice*$rate*$fxrates['rates']['MXN'];
echo round($result,2);
In PHP you can use number_format to control how many decimal places. Assuming you don't want to limit the whole number to just five characters.
echo number_format($numberToFormat, $numberOfDecimalPlaces);
Please better explain your question. Also, what have you tried?
This question already has answers here:
How to strip trailing zeros in PHP
(15 answers)
Show a number to two decimal places
(25 answers)
Closed 7 years ago.
This questions is kinda confusing, but here I am telling you the exact problem I have.
In database I have a column with datatype double(10,6), means the value can have upto 6 decimals depending on each user.
Some user have a value 5.22 say in this column.
Now when I echo this value in php, I want it to show 5.22 or 7.256 not 5.220000 or 7.256000.
I hope its clear.
Thanks.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to reformat a number with commas
Formatting numbers with thousands separator Smarty PHP
Format a number with grouped thousands
For example the following code:-
{php}echo $youtube->_views;{/php}
returns 2556789 and I want it formatted like this; 2,556,789
This topic says how to do it:
{$myvar|number_format:2:".":","}