# All files / extensions formatMoney.js

11.11% Statements 1/9
0% Branches 0/10
0% Functions 0/2
11.11% Lines 1/9

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19

    4x

     import { padEnd } from 'lodash';

    const trimZeroes = str => {
      if (str[str.length - 1] === '0') {
        return trimZeroes(str.slice(0, -1));
      } else if (str.indexOf('.') > str.length - 2) {
      }
      return padEnd(str, 2, '0');
    };

    export default money => {
      if (typeof money === 'string' || typeof money === 'number') {
        const [dollars, cents] = ('' + money).split('.');
        return `${dollars}.${trimZeroes(`${cents || '00'}00`)}`;
      }
      // we don't recognize this money type...
      return money;
    };