{"id":12673,"library":"wnumb","title":"wNumb: JavaScript Number & Money Formatting","description":"wNumb is a lightweight JavaScript utility designed specifically for number and money formatting. It enables developers to control aspects such as decimal places, thousands separators, and the addition of prefixes or suffixes to numerical values, facilitating clear and readable data presentation. The current stable version is 1.2.0, released in October 2019. The project appears to have an irregular release cadence, with no updates since 2019, suggesting it is currently in a maintenance phase rather than active development. Its core value lies in offering a focused, minimal API for common formatting needs, differentiating itself from more comprehensive internationalization libraries by prioritizing simplicity and a small footprint.","status":"maintenance","version":"1.2.0","language":"javascript","source_language":"en","source_url":"git://github.com/leongersen/wnumb","tags":["javascript"],"install":[{"cmd":"npm install wnumb","lang":"bash","label":"npm"},{"cmd":"yarn add wnumb","lang":"bash","label":"yarn"},{"cmd":"pnpm add wnumb","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"wNumb is typically consumed as a default export when using modern bundlers or CommonJS environments. It is not a named export.","wrong":"import { wNumb } from 'wnumb';","symbol":"wNumb","correct":"import wNumb from 'wnumb';"},{"note":"For Node.js or older environments using CommonJS, wNumb is imported as a module.","symbol":"wNumb (CommonJS)","correct":"const wNumb = require('wnumb');"},{"note":"When included via a <script> tag in a browser, wNumb is exposed globally as the 'wNumb' function.","symbol":"wNumb (Global)","correct":"const formatter = wNumb({...}); // Assumes wNumb script tag is present"}],"quickstart":{"code":"import wNumb from 'wnumb'; // For module environments like Node.js or bundlers\n// If using directly in browser via script tag, 'wNumb' is global.\n\n// Create a currency formatter for USD\nconst usdFormatter = wNumb({\n    decimals: 2,           // Number of decimals (e.g., 2 for $XX.XX)\n    mark: '.',             // Decimal separator\n    thousand: ',',         // Thousands separator\n    prefix: '$ ',\n    suffix: ' USD'\n});\n\nconsole.log(usdFormatter.to(12345.678));\n// Expected output: \"$ 12,345.68 USD\"\n\nconsole.log(usdFormatter.from('$ 5,432.10 USD'));\n// Expected output: 5432.1\n\n// Create a percentage formatter\nconst percentFormatter = wNumb({\n    decimals: 0,\n    suffix: '%'\n});\n\nconsole.log(percentFormatter.to(0.75));\n// Expected output: \"75%\"\n\nconsole.log(percentFormatter.from('99%'));\n// Expected output: 0.99\n\n// A simple number formatter with specific rounding\nconst numberFormatter = wNumb({\n    decimals: 3,\n    encoder: value => value * 2, // Example: custom encode function\n    decoder: value => value / 2  // Example: custom decode function\n});\n\nconsole.log(numberFormatter.to(10.1234));\n// Expected output: \"20.247\" (10.1234 * 2 = 20.2468, rounded to 3 decimals)","lang":"javascript","description":"Demonstrates how to create and use wNumb formatters for currency, percentages, and custom numeric transformations, including encoding and decoding values."},"warnings":[{"fix":"Update your formatter configurations to use `suffix` instead of `postfix`.","message":"The `postfix` option was renamed to `suffix` in version 1.1.0. While `postfix` is remapped internally for backward compatibility, relying on the old name is deprecated and may lead to unexpected behavior or removal in future updates.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Upgrade to wNumb version 1.0.2 or newer to resolve this display issue.","message":"When formatting small negative numbers with `decimals` set to 0, older versions (prior to 1.0.2) could display '-0' instead of '0'.","severity":"gotcha","affected_versions":"<1.0.2"},{"fix":"Upgrade to wNumb version 1.0.1 or newer to ensure correct decimal processing.","message":"Early versions (prior to 1.0.1) had issues with decimal handling, potentially leading to incorrect formatting or parsing of values with fractional components.","severity":"gotcha","affected_versions":"<1.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Upgrade your wNumb package to version 1.0.2 or higher.","cause":"You are using an older version of wNumb (prior to 1.0.2) which had a bug in rounding very small negative numbers.","error":"Formatter outputs '-0' for negative numbers with `decimals: 0`"},{"fix":"Upgrade your wNumb package to version 1.0.1 or higher.","cause":"Your wNumb version is older than 1.0.1, which contained a bug related to decimal processing.","error":"Unexpected behavior or incorrect parsing when handling decimal values."},{"fix":"Change your formatter configuration from `postfix: 'TEXT'` to `suffix: 'TEXT'`.","cause":"In version 1.1.0, the `postfix` option was renamed to `suffix`. While an internal remapping exists, direct use of `suffix` is recommended.","error":"The `postfix` option is ignored or does not apply the desired text."}],"ecosystem":"npm"}