# All files format.js

100% Statements 13/13
100% Branches 6/6
100% Functions 1/1
100% Lines 13/13

    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
    261x
    1x

    1x
    324x

    324x

    324x
    30x
    30x

    324x

    30x
    15x

    30x

    324x

     var round = Math.round
    var pow = Math.pow

    module.exports = function(aValue, multiplier, precision, unit) {
        var value = parseInt(aValue, 10) * multiplier
        // TODO: precision should be valid or df should invoke callback with `err`
        // This is a breaking change to be made after release 0.1.4
        var hasPrecision = typeof precision === 'number'
        var amount

        if (hasPrecision) {
            amount = pow(10, precision)
            value = round(value * amount) / amount
        }

        if (unit != null) {
            // NOTE: this is to always show decimals even if value is an integer
            if (hasPrecision) {
                value = value.toFixed(precision)
            }
            value += unit
        }

        return value
    }