js-number-beautifier
v1.0.4
Published
A friendly and easy to use number formatter and beautify.
Downloads
5
Maintainers
Readme
Js-Number-Beautifier
A easy to use JavaScript number formatter and beautifier for all JavaScript frameworks. The Js-Number-Beautifier make it easy to format you number and currencies in thousands, it gives the ability to use Hooks like useState allowing you format your numbers in real-time has your value changes.
Installation
npm
$ npm i js-number-beautifier
bower
$ bower install js-number-beautifier
Initialisation
To initilise the number formatter/beautifier you have to do this.
import NumberBeautify from "js-number-beautifier";
or
const NumberBeautify = require("js-number-beautifier");
NumberBeautify(value=593454.64, prefix="₦", suffix="k")
// returns ₦593,454.64k
Options
The number beautifier takes in this options:
- Value: the value to beautify or format and cannot be string.
- Prefix(Optional): a string value to add before the value like a currency sign or anything.
- Suffix(Optional): A string value to add at the back of the value
Using React useState has an example
import react, {useState} from 'react';
import NumberBeautify from 'js-number-beautifier';
const App = () => {
const [profit, setProfit] = useState();
const [capital, setCapital] = useState();
const handleChange = (e) => {
setCapital(e.target.value);
};
return(
<div>
<input
type="text"
value={NumberBeautify(capital, "₦", "k")}
placeholder="capital"
onChange={handleChange}
/>
<p>Profit: {NumberBeautify(`${profit}`, "$")}</p>
</div>
)
}