Number.tsx 713 Bytes
Newer Older
Maksym Tishchenko's avatar
Maksym Tishchenko committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import * as React from 'react';
import {WithTranslation, withTranslation} from "react-i18next";

interface INumber extends React.ClassAttributes<any>, WithTranslation {
  value: number;
  config?: Intl.NumberFormatOptions;
}


// Print a number
// TBD maybe use l10n instead?
class Number extends React.Component<INumber, any> {
  public constructor(props) {
    super(props);
  }

  public render() {
    const {value, config = {}, i18n} = this.props

    if (typeof value === 'number') {
      return <span>{ value.toLocaleString(i18n.language, { maximumFractionDigits: 6, ...config }) }</span>;
    } else {
      return <span>&mdash;</span>;
    }
  }
}

export default React.memo(withTranslation()(Number));