Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 9d50716

Browse files
authored
Merge pull request #971 from lightninglabs/fix-number-formatting-android
Fix number formatting android
2 parents 78c39ff + 8f15a44 commit 9d50716

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

mobile/App.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import 'node-libs-react-native/globals';
2+
import { Platform } from 'react-native';
3+
4+
// Polyfill ECMAScript Internationalization API on Android
5+
// See: https://github.com/facebook/react-native/issues/19410
6+
if (Platform.OS === 'android') {
7+
require('intl');
8+
require('intl/locale-data/jsonp/en-US');
9+
}
210

311
import App from '../src/view/main-mobile';
412

mobile/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
},
1919
"dependencies": {
2020
"expo": "^32.0.4",
21+
"intl": "^1.2.5",
2122
"locale-currency": "0.0.2",
2223
"mobx": "^4.5.0",
2324
"mobx-react": "^5.2.8",

src/helper.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export const formatNumber = val => {
1414
if (isNaN(num)) {
1515
num = 0;
1616
}
17-
return num.toLocaleString(undefined, { maximumFractionDigits: 8 });
17+
const options = { maximumFractionDigits: 8 };
18+
return new Intl.NumberFormat(undefined, options).format(num);
1819
};
1920

2021
/**
@@ -28,7 +29,8 @@ export const formatFiat = (val, currency) => {
2829
if (isNaN(num)) {
2930
num = 0;
3031
}
31-
return num.toLocaleString(undefined, { style: 'currency', currency });
32+
const options = { style: 'currency', currency };
33+
return new Intl.NumberFormat(undefined, options).format(num);
3234
};
3335

3436
/**
@@ -83,10 +85,8 @@ export const toAmount = (satoshis, settings) => {
8385
const num = settings.displayFiat
8486
? calculateExchangeRate(satoshis, settings)
8587
: satoshis / UNITS[settings.unit].denominator;
86-
return num.toLocaleString('en-US', {
87-
useGrouping: false,
88-
maximumFractionDigits: 8,
89-
});
88+
const options = { useGrouping: false, maximumFractionDigits: 8 };
89+
return new Intl.NumberFormat('en-US', options).format(num);
9090
};
9191

9292
/**

0 commit comments

Comments
 (0)