pronamic/wp-number 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pronamic/wp-number

Composer 安装命令:

composer require pronamic/wp-number

包简介

WordPress Number library.

README 文档

README

WordPress Number library.

Latest Stable Version Total Downloads Latest Unstable Version License codecov Coverage Status

Table of contents

Getting Started

Installation

composer require pronamic/wp-number

Usage

$number = Number::from_float( 123.50 )->add( 0.45 );

echo \esc_html( $number->format_i18n( 2 ) );

Design Principles

A number is a number

In general, a number is a number, not a string, and this means that any programming language treats a number as a number. Thus, the number by itself doesn't imply any specific format (like using .000021 instead of 2.1e-5). This is nothing different to displaying a number with leading zeros (like 0.000021) or aligning lists of numbers. This is a general issue you'll find in any programming language: if you want a specific format you need to specify it, using the format functions of your programming language.

Unless you specify the number as string and convert it to a real number when needed, of course. Some languages can do this implicitly.

https://stackoverflow.com/a/1471792

Number in exponential form / scientific notation

2.1E-5 is the same number as 0.000021. That's how it prints numbers below 0.001. Use printf() if you want it in a particular format.

Edit If you're not familiar with the 2.1E-5 syntax, you should know it is shorthand for 2.1×10-5. It is how most programming languages represent numbers in scientific notation.

https://stackoverflow.com/a/1471694

Leading zeros

In https://github.com/moneyphp/money it is not allowed to use leading zeros:

Leading zeros are not allowed

Source: https://github.com/moneyphp/money/search?q=leading+zero

This probably has somehting to do with the following user note:

Be careful with GMP - it considers leading zeros in a number string as meaning the number is in octal, whereas 'bc' doesn't:

gmp_strval("000100", 10) => 64

bcmul("000100", "1") => 100

Source: https://www.php.net/manual/en/book.gmp.php#106521

<?php
$a = 1234; // decimal number
$a = 0123; // octal number (equivalent to 83 decimal)
$a = 0x1A; // hexadecimal number (equivalent to 26 decimal)
$a = 0b11111111; // binary number (equivalent to 255 decimal)
$a = 1_234_567; // decimal number (as of PHP 7.4.0)
?>

Source: https://www.php.net/manual/en/language.types.integer.php

A leading zero in a numeric literal means "this is octal". But don't be confused: a leading zero in a string does not. Thus: $x = 0123; // 83 $y = "0123" + 0 // 123

Source: https://www.php.net/manual/en/language.types.integer.php#111523

Links

Pronamic - Work with us

pronamic/wp-number 适用场景与选型建议

pronamic/wp-number 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 95.38k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「i18n」 「wordpress」 「number」 「calculator」 「Double」 「int」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pronamic/wp-number 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pronamic/wp-number 我们能提供哪些服务?
定制开发 / 二次开发

基于 pronamic/wp-number 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 95.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 15
  • 依赖项目数: 15
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2021-03-09