https://github.com/bagilevi/bs-decimal
Decimal number utilities for ReasonML
https://github.com/bagilevi/bs-decimal
Last synced: 13 days ago
JSON representation
Decimal number utilities for ReasonML
- Host: GitHub
- URL: https://github.com/bagilevi/bs-decimal
- Owner: bagilevi
- License: mit
- Created: 2018-10-13T13:58:44.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-10T11:23:37.000Z (over 6 years ago)
- Last Synced: 2025-04-21T17:57:52.094Z (27 days ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bs-decimal
Decimal number functions for ReasonML - experimental stage
Decimals are represented as a tuple of mantissa and exponent, both `int`.
It supports basic mathematical operations and conversion to and from string.## Installation
yarn add bs-decimal
Add it to `bs-dependencies` in `bsconfig.json`, e.g:
{
"name": "myapp",
"sources": "src",
"bs-dependencies": ["bs-decimal"]
}## Usage
open Decimal;
let a = dec("1.50");
let b = dec("2");add(a, b)->to_s; # => 3.50
subtract(a, b)->to_s; # => -0.50
multiply(a, b)->to_s; # => 3.00
divide(a, b)->to_s; # => 0.75divide(a, b, ~precision=1)->to_s; # => 0.7
divide(a, b, ~round=1)->to_s; # => 0.8## Running tests
yarn test
During development:
# console 1 - watch & build .re -> .js
yarn start# console 2 - watch & run tests
yart test:watch## Licence
MIT - See LICENCE file.