PHP format for Lakh and Crore [duplicate] - php

This question already has answers here:
Is there any PHP function to convert number to currency with thousands separators?
(2 answers)
Closed 7 years ago.
Want to format number in php like 1,00,00,00,000. I am trying the following function
number_format($var['count'])
but it is giving me following answer 1,000,000,000
Thanks and Regards

You can try this, to do additional formatting read through PHP's documentation: PHP.NET - Money Format
$dollar = 6000000000;
setlocale(LC_MONETARY, 'en_IN');
echo $dollar = money_format('%!i', $dollar);
Output:
6,00,00,00,000.00

Try this
$number = 123554646;
setlocale(LC_MONETARY,"en_IN");
echo money_format("The price is %i", $number);
Output
The price is INR 12,35,54,646.00
Check Phpfiddle Preview

Related

How to set a decimal value up to 8 decimal places in php [duplicate]

This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 3 years ago.
I want to show amount of bitcoins up to 8 decimal points. I have stored the value in Satoshi but when I try to convert the satoshi to BTC by dividing the satoshi value with 100000000 I am getting invalid result. here is my code.
$res = 3535/100000000;
echo $res;
the output of the above code is 3.535E-5 isntead 0.00003535.
please tell me the proper solution.
echo number_format(3535/100000000, 8);
Where 8 is the count of 0's. For example for 3535/1000000000 you need to write
echo number_format(3535.0/1000000000, 9);

Php change 5.0E-5 into 0.00000050 [duplicate]

This question already has answers here:
Display float value w/o scientific notation
(4 answers)
Closed 5 years ago.
I am working on my site about bitcoins. And people can have balances there. I am btw working in php. In my $user_data["balance"] the value is 50. And I want that to get converted by php into 0.00000050. So I tried this:
$balance = $user_data["balance"] / 1000000;
But what I get from it, is this: 5.0E-5. How to change it into 0.00000050?
I would be really thankfull if somebody would help me!
Use number_format to get results with 8 decimals.
Example-
$balance = number_format($user_data["balance"] / 1000000,8,".","");
echo $balance; //output will 0.00005000
But if you want 0.00000050 then divide it by 100000000
Example
$balance = number_format($user_data["balance"] / 100000000,8,".","");
echo $balance; //output will 0.00000050

PHP check number have no decimals than add two decimal number [duplicate]

This question already has answers here:
PHP, Format Number to have always have 2 decimal places
(2 answers)
Closed 5 years ago.
Input:
(1) 2
(2) 2.3
PHP:
<?php if(is_int($ledger['Amount'])){$Amount = $ledger['Amount'].'.00';}else{$Amount = $ledger['Amount'];};?>
Output:
(1) 2.00
(2) 2.30
Anyone can please help me How can I get my expected output? Sorry for weak English and please help me for improving quality of this question.
Do not invent the wheel:
echo number_format(2, 2); // 2.00
echo number_format(2.3, 2); // 2.30

How to append zero after 4.5 to make it 4.50 in PHP? [duplicate]

This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 7 years ago.
I know it may be a silly one and it may be duplicate question as well, but I can't find any proper question posted before(may be its my incapability)
I have a value fetched from DB... its say like
4.5 which should be 4.500
0.01 which should be 0.010
11 which should be 11.000
How can I achieve this in PHP?
Simply format it with sprinft to make it a floating point number to 2 decimal places.
echo sprintf("%.2f", 4.5);
https://eval.in/378771
If you change the 2 to a 3 you will get your format you've listed.
echo sprintf("%.3f", 4.5) . PHP_EOL;
echo sprintf("%.3f", 0.01) . PHP_EOL;
echo sprintf("%.3f", 11) . PHP_EOL;
https://eval.in/378773
php.net/number_format
number_format(4.5,2);
Use the function number_format
Trailing zeros to the right of a decimal point is not supported in PHP. You need to format the number to string.
$value = number_format($value,3);
Modern way is to use NumberFormatter which formats numbers according to set locale.
$fmt = new NumberFormatter('en-US', NumberFormatter::DECIMAL);
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 3);
$fmt->format(1234567.891234567890000);
If You use mysql then Use FORMAT function
like SELECT FORMAT(4.5,4)
also str_pad(4.5,STR_PAD_RIGHT)
for more http://php.net/manual/zh/function.str-pad.php

How Can I change a number to string [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Is there an easy way to convert a number to a word in PHP?
Recently I needed to change a number to string just like below in php
$str=100;
{ Here will be the code which will return One Hundred not 100}
so $str=150 then will return one hundred fifty
How can I do it. How can I change the number to text in php (NB: number will be random)
please help me
Use Numbers_Words Pear package.
Example.
require('Numbers/Words.php');
$number = 150;
$nw = new Numbers_Words();
$numw = $nw->toWords($number);
echo $numw; //one hundred fifty
The solution to this problem has been suggested in the comments of the php documentation at the following location: http://www.php.net/manual/en/function.number-format.php#97020
Hope that helps
There is a PEAR package that will do this for you ...
http://pear.php.net/package-info.php?package=Numbers_Words

Categories