Skip to content
/ nprintf Public

The js version's 'printf',just for number, like 'c' language.类似c里的printf方法,主要针对数字类型格式化。

License

Notifications You must be signed in to change notification settings

suchjs/nprintf

Repository files navigation

nprintf

npm version  Build Status Coverage Status

将一个数字格式化,转换方式和 c 语言的 printf 方法保持一致。

Format numbers like c printf.

How to use

npm install --save nprintf
import printf from 'nprintf';
console.log(printf('%.2f', 11)); // 11.00, type: string
console.log(printf('%.2f', 11.355)); // 11.36 type: number

Attention

注意格式化模板需要符合以下正则,否则将抛出错误。

just support format rule like this. /^%([#\-+0 ]*)?([1-9]\d*)?(?:\.(\d+))?([dfeEoxXi])(%)?$/

Questions & Bugs?

Welcome to report to us with issue if you meet any question or bug. Issue

License

MIT License.

About

The js version's 'printf',just for number, like 'c' language.类似c里的printf方法,主要针对数字类型格式化。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published