当前位置: 首页>>代码示例>>PHP>>正文


PHP Number::convertToWords方法代码示例

本文整理汇总了PHP中Number::convertToWords方法的典型用法代码示例。如果您正苦于以下问题:PHP Number::convertToWords方法的具体用法?PHP Number::convertToWords怎么用?PHP Number::convertToWords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Number的用法示例。


在下文中一共展示了Number::convertToWords方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: convertToWords

 public static function convertToWords($number)
 {
     $hyphen = '-';
     $conjunction = ' and ';
     $separator = ', ';
     $negative = 'negative ';
     $decimal = ' point ';
     $dictionary = array(0 => 'zero', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', 19 => 'nineteen', 20 => 'twenty', 30 => 'thirty', 40 => 'fourty', 50 => 'fifty', 60 => 'sixty', 70 => 'seventy', 80 => 'eighty', 90 => 'ninety', 100 => 'hundred', 1000 => 'thousand', 1000000 => 'million', 1000000000 => 'billion', 1000000000000 => 'trillion', 1000000000000000 => 'quadrillion', 1000000000000000000 => 'quintillion');
     if (!is_numeric($number)) {
         return false;
     }
     if ($number >= 0 && (int) $number < 0 || (int) $number < 0 - PHP_INT_MAX) {
         // overflow
         trigger_error('convertToWords only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX, E_USER_WARNING);
         return false;
     }
     if ($number < 0) {
         return $negative . Number::convertToWords(abs($number));
     }
     $string = $fraction = null;
     if (strpos($number, '.') !== false) {
         list($number, $fraction) = explode('.', $number);
     }
     switch (true) {
         case $number < 21:
             $string = $dictionary[$number];
             break;
         case $number < 100:
             $tens = (int) ($number / 10) * 10;
             $units = $number % 10;
             $string = $dictionary[$tens];
             if ($units) {
                 $string .= $hyphen . $dictionary[$units];
             }
             break;
         case $number < 1000:
             $hundreds = $number / 100;
             $remainder = $number % 100;
             $string = $dictionary[$hundreds] . ' ' . $dictionary[100];
             if ($remainder) {
                 $string .= $conjunction . Number::convertToWords($remainder);
             }
             break;
         default:
             $baseUnit = pow(1000, floor(log($number, 1000)));
             $numBaseUnits = (int) ($number / $baseUnit);
             $remainder = $number % $baseUnit;
             $string = Number::convertToWords($numBaseUnits) . ' ' . $dictionary[$baseUnit];
             if ($remainder) {
                 $string .= $remainder < 100 ? $conjunction : $separator;
                 $string .= Number::convertToWords($remainder);
             }
             break;
     }
     if (null !== $fraction && is_numeric($fraction)) {
         $string .= $decimal;
         $words = array();
         foreach (str_split((string) $fraction) as $number) {
             $words[] = $dictionary[$number];
         }
         $string .= implode(' ', $words);
     }
     return $string;
 }
开发者ID:Mojolagbe2014,项目名称:mojotiesiaigurupu,代码行数:64,代码来源:Number.php

示例2: strtoupper

echo SITE_URL;
?>
courses/" class="btn btn-primary text-default">View Courses!!!</a></div>
                                        </div>
                                    </div>
                                    <div class="col-md-8 col-sm-7">
                                        <div class="content-pad single-event-detail">
                                            <div class="event-detail">
                                                <div class="event-speaker"></div><!--/event-speaker-->
                                                <div class="event-info row content-pad">
                                                    <div class="col-md-6 col-sm-6">
                                                        <a href="<?php 
echo SITE_URL;
?>
courses/" > <i class="fa fa-book"></i> Courses Available: <?php 
echo strtoupper(Number::convertToWords(Course::getSingleCategoryCount($dbObj, $categoryObj->id)));
?>
</a>
                                                        
                                                    </div>
                                                </div><!--/event-info-->
                                            </div><!--/event-detail-->
                                            <div class="event-content">
                                                <div class="content-dropcap">
                                                    <h3>Category Details</h3>
                                                    <?php 
echo $categoryObj->description;
?>
                                                </div>
                                               
                                                <div class="event-more-detail">
开发者ID:Mojolagbe2014,项目名称:mojotiesiaigurupu,代码行数:31,代码来源:category.php


注:本文中的Number::convertToWords方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。