【问题标题】:How Can I change a number to string [duplicate]如何将数字更改为字符串 [重复]
【发布时间】:2012-02-04 22:02:22
【问题描述】:

可能重复:
Is there an easy way to convert a number to a word in PHP?

最近我需要将一个数字更改为字符串,就像下面的 php 中一样

$str=100;

{ Here will be the code which will return One Hundred not 100}

所以 $str=150 然后将返回 150

我该怎么做。如何将数字更改为 php 中的文本(NB: 数字将是随机的) 请帮帮我

【问题讨论】:

  • 你有没有尝试过,或者你只是想让别人为你编码?
  • 呃,作业?无论如何:$expontents = array( 1000000000 => 'billion', 1000000 = 'million', 1000 => 'thousand', 100 => 'hundred'); $decades = array( 10 => 'ten', 20 => 'twenty'), $numbers = array( 'zero', 'one', 'two'), $specials => array( 11 => 'eleven')%<>+-*/, floor 是要走的路:)

标签: php


【解决方案1】:

使用Numbers_Words梨包。

示例。

 require('Numbers/Words.php');
 $number = 150;
 $nw = new Numbers_Words();
 $numw = $nw->toWords($number);

 echo $numw; //one hundred fifty

【讨论】:

  • 有没有人尝试过大于 999,999,999(十亿及以上)的数字? 1,000,000,000 人说“一千万”!?
【解决方案2】:

此问题的解决方案已在以下位置的 php 文档的 cmets 中提出:http://www.php.net/manual/en/function.number-format.php#97020

希望有帮助

【讨论】:

    【解决方案3】:

    有一个 PEAR 包可以为你做到这一点......

    http://pear.php.net/package-info.php?package=Numbers_Words

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 2018-02-12
      • 1970-01-01
      • 2021-10-20
      相关资源
      最近更新 更多