Format.php 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fecshop\services\helper;
  10. use fecshop\services\Service;
  11. /**
  12. * Format services.
  13. * @author Terry Zhao <2358269014@qq.com>
  14. * @since 1.0
  15. */
  16. // use \fecshop\services\helper\Format;
  17. class Format extends Service
  18. {
  19. /**
  20. * @param $number | Float
  21. * @param $bits | Int
  22. * @return $number | Float
  23. * 返回格式化形式的float小数,譬如2 会变成2.00
  24. */
  25. public function number_format($number, $bits = 2)
  26. {
  27. return number_format($number, $bits, '.', '');
  28. }
  29. /**
  30. * @param $day | Int 多少天之前
  31. * 返回最近xx天的日期数组
  32. */
  33. public function getPreDayDateArr($day)
  34. {
  35. $arr = [];
  36. for ($i=$day; $i>=0; $i--) {
  37. $str = date("Y-m-d", strtotime("-$i day"));
  38. $arr[$str] = 0;
  39. }
  40. return $arr;
  41. }
  42. }