You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Alternatively, if you just want to parse a `string` without conversion, you can use the [`parse`](#parseexpression) function, which returns an `object` with parsing results:
130
+
Alternatively, if you just want to parse a `string` without conversion you can use the [`parse`](#parseexpression) function which returns an `object` with parsing results:
125
131
126
132
```js
127
-
const {parse} =require('cashify');
133
+
import {parse} from'cashify';
128
134
129
135
parse('10 EUR to GBP'); //=> {amount: 10, from: 'EUR', to: 'GBP'}
130
136
```
131
137
132
-
**Note:** If you want to use full parsing, you need to pass a `string`with specific format:
138
+
**Note:** If you want to use full parsing, you need to pass a `string`in a specific format:
133
139
134
140
```
135
141
10 usd to pln
@@ -139,15 +145,41 @@ parse('10 EUR to GBP'); //=> {amount: 10, from: 'EUR', to: 'GBP'}
139
145
140
146
You can use `to`, `in` or `as` to separate the expression (case insensitive). Used currencies name case doesn't matter, as cashify will automatically convert them to upper case.
141
147
142
-
<aid="integration"></a>
148
+
<aid="integration-bigjs"></a>
149
+
150
+
### Integration with [big.js](https://github.com/MikeMcl/big.js/)
151
+
152
+
[big.js](https://github.com/scurker/currency.js/) is a small JavaScript library for arbitrary-precision decimal arithmetic. You can use it with cashify to make sure you won't run into floating point issues:
153
+
154
+
```js
155
+
import {Cashify} from'cashify';
156
+
importBigfrom'big.js';
157
+
158
+
constrates= {
159
+
EUR:0.8235,
160
+
USD:1
161
+
};
162
+
163
+
constcashify=newCashify({base:'USD', rates});
164
+
165
+
constresult=cashify.convert(1, {
166
+
from:'USD',
167
+
to:'EUR',
168
+
BigJs: Big
169
+
});
170
+
171
+
console.log(result); //=> 8.235 (without big.js you would get something like 0.8234999999999999)
172
+
```
173
+
174
+
<aid="integration-currencyjs"></a>
143
175
144
176
### Integration with [currency.js](https://github.com/scurker/currency.js/)
145
177
146
-
[currency.js](https://github.com/scurker/currency.js/) is a small and lightweight library for working with currency values. It works great with cashify. In the following example we are using it to format the conversion result:
178
+
[currency.js](https://github.com/scurker/currency.js/) is a small and lightweight library for working with currency values. It integrates well with cashify. In the following example we are using it to format the conversion result:
As you can see, money.js doesn't handle currencies correctly and therefore a floating point issues are occuring. Even though there's just a minor discrepancy between the results, if you're converting large amounts, that can add up.
311
355
312
-
Cashify solves this problem the same way as [currency.js](https://github.com/scurker/currency.js/) - by working with integers behind the scenes. This should be okay for most reasonable values of currencies.
356
+
Cashify solves this problem the same way as [currency.js](https://github.com/scurker/currency.js/) - by working with integers behind the scenes. **This should be okay for most reasonable values of currencies**; if you want to avoid all floating point issues, see [integration with big.js]().
313
357
314
358
## Related projects
315
359
316
-
*[nestjs-cashify](https://github.com/vahidvdn/nestjs-cashify) - nodejs cashify module for nestjs
317
-
*[currency.js](https://github.com/scurker/currency.js/) - Lightweight javascript library for working with currency values.
360
+
*[nestjs-cashify](https://github.com/vahidvdn/nestjs-cashify) - Node.js Cashify module for Nest.js.
318
361
*[cashify-rs](https://github.com/xxczaki/cashify-rs) - Cashify port for Rust.
0 commit comments