English 中文(简体)
显示字数改为方数
原标题:Convert string word number into string number php
  • 时间:2012-01-13 19:12:20
  •  标签:
  • php
  • html
  • web

我有几句话,其价值是“53ILL”。

            $number="53 MILLION";

我想这个数字是53 000 000 000美元。 如何做到这一点? 我使用“原状”功能,但无uck。

提前感谢!

$number="53 MILLION";

     $number= str_replace($number, "MILLION", "000,000");

    echo $number; //000,000 instead of 53,000,000
最佳回答

在耶稣所说的基础上,建立这些数字的简单功能是:

function declare_number($number_string){
    $find_replace = array(
          HUNDRED   =>   00 ,
          THOUSAND  =>   ,000 ,
          MILLION   =>   ,000,000 ,
          BILLION   =>   ,000,000,000 
    );
    return str_ireplace(array_keys($find_replace),$find_replace,$number_string);
}

这也能够转换为8亿人=80万人。

问题回答

为什么不要把你的扼杀分开,在你的阵列中寻找“ILL”,然后将其换成“000 000”,然后将其全部归回呢? 我恳请你利用空间进行分裂。

如果你只有100万人,就使用:

$number = str_replace(  million ,  000000 , $number);

不知道购买力平价,但算法

用于“5 300万、2 100万和8 100万”的Algorithm:

Size String Translation Table = [{"Million", 1000000},{"Thousand", 1000}, etc...]
counter = 0
--Scan from top of string to end:
----until comma
------scan integer - "53"
------scan size string - "Million"
------multiply integer by size string translation - "53 * 1000000"
------Add to the main counter - counter += "53000000"
----loop
--end

Depends how example is your question Your real case could be: convert 53 MILLION 39 TOUSEND 334 into 53,039,334 etc.

因此,算法是要在有数字的地方打脚石,记住它。 <代码> THOUSEND, MILLION, 等 , 即可乘你身边的脚步和编号。 最后,加上不成倍的东西。 之后,你有数字。

Convert the number into number-string (53039334) and, going from end, after each 3 digits add coma, and here you have what you need :)





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签