This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Converting a number (1, 2, 3) to a string (one, two, three) in PHP
I have a form in which products will be listed out when,i clich total chk box it will be calculated but,it will be integera only,i want this to print in words.
For eg:217 it should print in words two hundred seven only. Hope,this is clear.
Thnx in advance
PEAR's Numbers Words is old, but competent.
The duplicate question seems to answer this quite well, DAFFODIL, have a look there. You will have to have PEAR installed. Easiest way is to try Numbers_Words::toWords(200) and see if that throws up an error.
Related
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:
MySQL: Select Random Entry, but Weight Towards Certain Entries
(11 answers)
Closed 8 years ago.
I'm working on a simple advertisement script, I have a database with all the ads and a weight.
The ad is a picture and the weight is a number from 1 to 20 depending on it's importance (1 shows up rarely and 20 shows up a lot.
But if I'm getting this information from my database how do I sort and choose an ad to display? So can I put a weight on a variabele in a creative way? It's possible to make and array for each weight point and then select a random ad from that array but is there a better alternative?
#Dagon is correct. Use the example from that other question. Again Dagon found it here: MySQL: Select Random Entry, but Weight Towards Certain Entries The comments are really helpful. You basically multiple that row by its weight. To add to that question and answers I would add the rows into an array and then randomly pick one (one array value) to display. When something has more weight just place it in that array times its weight.
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.
This question already has answers here:
int((0.1+0.7)*10) = 7 in several languages. How to prevent this?
(7 answers)
Closed 9 years ago.
Can anybody figure out how the following statement evaluates to 7?
echo (int)( (0.1+0.7)*10 );
I was trying the operator precedence in PHP. So, if there is anybody who can help, it will be highly appreciated.
If you remove the (int) part, and run the follwing code instead:
echo number_format(((0.1+0.7)*10), 20);
The output will be 7.99999999999999911182. This value parsed to an integer will result to 7, as parsing a value to an integer will always floor the value.
Reading the following article should give you an idea of what's going on here.
In short, double values are always a binary value, and through that a 'product of 2^n', whichever will be the nearest to the decimal you said it should be. And with 2^n you dont have any chance to reach exactly 0.1.
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:".":","}