How to use the conseiljs.AttrbuteDataType.DECIMAL function in conseiljs

To help you get started, we’ve selected a few conseiljs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Cryptonomic / Arronax / src / utils / general.ts View on Github external
if (!truncate) {
            minimumFractionDigits = 6;
            maximumFractionDigits = 6;
        } else if (value < 10000) {
            minimumFractionDigits = 6;
            maximumFractionDigits = 6;
        } else if (value < 100000) {
            minimumFractionDigits = 4;
            maximumFractionDigits = 4;
        } else if (value < 1000000000) {
            minimumFractionDigits = 2;
            maximumFractionDigits = 2;
        }

        t = (new Intl.NumberFormat(window.navigator.languages[0], { style: 'decimal', minimumFractionDigits, maximumFractionDigits })).format(d);
    } else if (attribute.dataType === AttrbuteDataType.DECIMAL) {
        if (Number.isInteger(value)) { // HACK: until accounts.block_level reports as 'Int'
            t = (new Intl.NumberFormat(window.navigator.languages[0], { style: 'decimal', useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 1 })).format(value);
        } else {
            t = (new Intl.NumberFormat(window.navigator.languages[0], { style: 'decimal', minimumFractionDigits: 6, maximumFractionDigits: 6 })).format(value);
        }
    } else if (attribute.dataType === AttrbuteDataType.CURRENCY) {
        t = (new Intl.NumberFormat(window.navigator.languages[0], { style: 'decimal', minimumFractionDigits: 6, maximumFractionDigits: 6 })).format(value);
    }

    if (attribute.dataType === AttrbuteDataType.CURRENCY) {
        if (attribute.currencySymbol !== undefined) {
            t = `${attribute.currencySymbol} ${t}`;
        } else if (attribute.currencySymbolCode !== undefined) {
            t = `${String.fromCharCode(attribute.currencySymbolCode)} ${t}`;
        }
    }
github Cryptonomic / Arronax / src / components / CustomTableRow / index.tsx View on Github external
const formatAggregatedValue = (attribute: AttributeDefinition, value: any, aggregation: ConseilFunction) => {
    let aggregationAttribute = { ...attribute };

    switch (aggregation) {
        case ConseilFunction.count: 
            aggregationAttribute.dataType = AttrbuteDataType.INT;
            break;
        default:
            aggregationAttribute.dataType = attribute.dataType === AttrbuteDataType.CURRENCY ? AttrbuteDataType.CURRENCY : AttrbuteDataType.DECIMAL;
            break;
    }

    return formatNumber(Number(value), aggregationAttribute);
}
github Cryptonomic / Arronax / src / utils / render.tsx View on Github external
const formatAggregatedValue = (attribute: AttributeDefinition, value: any, aggregation: ConseilFunction) => {
      let aggregationAttribute = { ...attribute };
  
      switch (aggregation) {
          case ConseilFunction.count: 
              aggregationAttribute.dataType = AttrbuteDataType.INT;
              break;
          default:
              aggregationAttribute.dataType = attribute.dataType === AttrbuteDataType.CURRENCY ? AttrbuteDataType.CURRENCY : AttrbuteDataType.DECIMAL;
              break;
      }
  
      return formatNumber(Number(value), aggregationAttribute);
  }
github Cryptonomic / Arronax / src / utils / general.ts View on Github external
export const formatNumber = (value: number, attribute: AttributeDefinition, truncate: boolean = true) => {
    if (value === undefined) { return ''; }

    let t = '';
    if (attribute.dataType === AttrbuteDataType.INT) {
        t = (new Intl.NumberFormat(window.navigator.languages[0], { style: 'decimal', useGrouping: false, minimumFractionDigits: 0, maximumFractionDigits: 1 })).format(value);
    } else if (attribute.scale !== undefined && (attribute.dataType === AttrbuteDataType.DECIMAL || attribute.dataType === AttrbuteDataType.CURRENCY)) {
        const d = value / Math.pow(10, attribute.scale);
        let minimumFractionDigits = 0;
        let maximumFractionDigits = 0;
        if (!truncate) {
            minimumFractionDigits = 6;
            maximumFractionDigits = 6;
        } else if (value < 10000) {
            minimumFractionDigits = 6;
            maximumFractionDigits = 6;
        } else if (value < 100000) {
            minimumFractionDigits = 4;
            maximumFractionDigits = 4;
        } else if (value < 1000000000) {
            minimumFractionDigits = 2;
            maximumFractionDigits = 2;
        }