﻿function opportunityFormatter(cellvalue, options, rowObject) {
    return "£" + numberFormatter(cellvalue, options, rowObject);
}

function numberFormatter(cellvalue, options, rowObject) {
    var value = parseInt(cellvalue + '');
    value = value > 999999
          ? formatNumber(value / 1000000) + 'M'
          : formatNumber(value);
    return value;
}

function formatNumber(value) {
    value = value + '';
    var parts = value.split('.');
    var units = parts[0];
    var decimals = parts.length > 1 ? '.' + parts[1].substring(0, 1) : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(units)) {
        units = units.replace(rgx, '$1' + ',' + '$2');
    }
    return units + decimals;
}

