components_node/functions-generic.js
/**
     * Data treatment to read values.
     * @static
     * @param {string} valueData 
     * @param {int} valueType 1 - general number | 2 - system currency | 3 - decimal | 4 - system currency (with decimals)
     * @param {*} specialInstructions 
     * @returns {int | double}
     * @example
     * SyncSystemNS.FunctionsGeneric.valueMaskWrite(variableNameOrText, 2)
     */
Data treatment to read values.
Data treatment to read values .
static valueMaskRead(valueData, configCurrency = "$", valueType = 2, specialInstructions = null)
    {
        let strReturn = "";
        let strValue = valueData;
        if(strValue !== null && typeof(strValue) !== "undefined")
        {
            BigNumber.config({
                DECIMAL_PLACES: 30,
                FORMAT: {
                    decimalSeparator: '.', 
                }
            });
            let bnStrValue = new BigNumber(strValue.toString()); 
            if(valueType == 1)
            {
                bnStrValue = bnStrValue.integerValue();
                strReturn = bnStrValue;
            }
            if(valueType == 2)
            {
                bnStrValue = bnStrValue.toFixed();
                if(bnStrValue.includes("."))
                {
                    bnStrValue = new BigNumber(bnStrValue).toFormat(2); 
                    bnStrValue = bnStrValue.replace(/\./g, "");
                }
                if(bnStrValue.length < 3)
                {
                    bnStrValue = "00" + bnStrValue.toString();
                }
                let strDecimal = bnStrValue.substr((bnStrValue.length - 2), bnStrValue.length);
                let bnStrValueFormated = new BigNumber(bnStrValue.substr(0, (bnStrValue.length - 2)) + "." + strDecimal);
                if(configCurrency == "R$")
                {
                    BigNumber.config({
                        FORMAT: {
                            prefix: '', 
                            decimalSeparator: ',', 
                            groupSeparator: '.', 
                            groupSize: 3 
                        }
                    });
                }
                if(configCurrency == "$")
                {
                    BigNumber.config({
                        FORMAT: {
                            prefix: '', 
                            decimalSeparator: '.', 
                            groupSeparator: ',', 
                            groupSize: 3 
                        }
                    });
                }
                strReturn = bnStrValueFormated.toFormat(2);
            }
            if(valueType == 3)
            {
                bnStrValue = bnStrValue.toFixed();
                strReturn = bnStrValue;
            }
            if(valueType == 4)
            {
                bnStrValue = bnStrValue.toFixed();
                if(bnStrValue.includes("."))
                {
                    bnStrValue = new BigNumber(bnStrValue).toFormat(2); 
                    bnStrValue = bnStrValue.replace(/\./g, "");
                }
                if(bnStrValue.length < 3)
                {
                    bnStrValue = "00" + bnStrValue.toString();
                }
                let strDecimal = bnStrValue.substr((bnStrValue.length - 2), bnStrValue.length);
                let bnStrValueFormated = new BigNumber(bnStrValue.substr(0, (bnStrValue.length - 2)) + "." + strDecimal);
                if(configCurrency == "R$")
                {
                    BigNumber.config({
                        FORMAT: {
                            prefix: '', 
                            decimalSeparator: ',', 
                            groupSeparator: '.', 
                            groupSize: 3 
                        }
                    });
                }
                if(configCurrency == "$")
                {
                    BigNumber.config({
                        FORMAT: {
                            prefix: '', 
                            decimalSeparator: '.', 
                            groupSeparator: ',', 
                            groupSize: 3 
                        }
                    });
                }
                strReturn = bnStrValueFormated.toFormat(2);
            }
             //working
        }
        return strReturn;
    }
static valueMaskRead ( valueData , configCurrency = "$" , valueType = 2 , specialInstructions = null ) { let strReturn = "" ; let strValue = valueData ; if ( strValue !== null && typeof ( strValue ) !== "undefined" ) { BigNumber . config ( { DECIMAL_PLACES : 30 , FORMAT : { decimalSeparator : '.' , } } ) ; let bnStrValue = new BigNumber ( strValue . toString ( ) ) ; if ( valueType == 1 ) { bnStrValue = bnStrValue . integerValue ( ) ; strReturn = bnStrValue ; } if ( valueType == 2 ) { bnStrValue = bnStrValue . toFixed ( ) ; if ( bnStrValue . includes ( "." ) ) { bnStrValue = new BigNumber ( bnStrValue ) . toFormat ( 2 ) ; bnStrValue = bnStrValue . replace ( / \. / g , "" ) ; } if ( bnStrValue . length < 3 ) { bnStrValue = "00" + bnStrValue . toString ( ) ; } let strDecimal = bnStrValue . substr ( ( bnStrValue . length - 2 ) , bnStrValue . length ) ; let bnStrValueFormated = new BigNumber ( bnStrValue . substr ( 0 , ( bnStrValue . length - 2 ) ) + "." + strDecimal ) ; if ( configCurrency == "R$" ) { BigNumber . config ( { FORMAT : { prefix : '' , decimalSeparator : ',' , groupSeparator : '.' , groupSize : 3 } } ) ; } if ( configCurrency == "$" ) { BigNumber . config ( { FORMAT : { prefix : '' , decimalSeparator : '.' , groupSeparator : ',' , groupSize : 3 } } ) ; } strReturn = bnStrValueFormated . toFormat ( 2 ) ; } if ( valueType == 3 ) { bnStrValue = bnStrValue . toFixed ( ) ; strReturn = bnStrValue ; } if ( valueType == 4 ) { bnStrValue = bnStrValue . toFixed ( ) ; if ( bnStrValue . includes ( "." ) ) { bnStrValue = new BigNumber ( bnStrValue ) . toFormat ( 2 ) ; bnStrValue = bnStrValue . replace ( / \. / g , "" ) ; } if ( bnStrValue . length < 3 ) { bnStrValue = "00" + bnStrValue . toString ( ) ; } let strDecimal = bnStrValue . substr ( ( bnStrValue . length - 2 ) , bnStrValue . length ) ; let bnStrValueFormated = new BigNumber ( bnStrValue . substr ( 0 , ( bnStrValue . length - 2 ) ) + "." + strDecimal ) ; if ( configCurrency == "R$" ) { BigNumber . config ( { FORMAT : { prefix : '' , decimalSeparator : ',' , groupSeparator : '.' , groupSize : 3 } } ) ; } if ( configCurrency == "$" ) { BigNumber . config ( { FORMAT : { prefix : '' , decimalSeparator : '.' , groupSeparator : ',' , groupSize : 3 } } ) ; } strReturn = bnStrValueFormated . toFormat ( 2 ) ; } } return strReturn ; }
Data treatment to read values.
Data treatment to read values .
//static valueMaskRead(valueData, configCurrency, valueType, specialInstructions) //valueType: 1 - general number | 2 - system currency | 3 - decimal //Default values. //---------------------- /*
        if(configCurrency === undefined) {
            configCurrency = "$";
        }
        if(valueType === undefined) {
            valueType = 2;
        }
        if(specialInstructions === undefined) {
            specialInstructions = null;
        }
        */ //---------------------- //Variables. //---------------------- //---------------------- //Logic. //if(strValue !== null || typeof(strValue) !== "undefined") //Set default configuration. //Note: Check if this configuration can be applied only to an instance. //EXPONENTIAL_AT: 1000, // decimal separator //let n1 = new bigDecimal(strValue.toString()); //let n1 = new bigDecimal(strValue); //documentation: https://mikemcl.github.io/bignumber.js/ //let n1 = new BigNumber("12312312312312312312312311.000000000000000000000000000000"); //let strDecimal; //let bnStrValueFormated = new BigNumber(); /*var formatValueBR = new Intl.NumberFormat('pt-BR', {
                //style: 'currency',
                currency: 'BRL',
                minimumFractionDigits: 2,
            });
            var formatValueUS = new Intl.NumberFormat('en-US', {
                //style: 'currency',
                currency: 'USD',
                minimumFractionDigits: 2,
            });*/ //Generic number. //bnStrValue = bnStrValue.toFixed(0); //bnStrValue = bnStrValue.toFixed(2); //System currency. //Check if it´s a decimal. //reduce to just 2 decimal spaces //console.log("bnStrValue (valueMaskRead)=", bnStrValue); //debug //Ajust input number. //Currency. //R$ (Real) // string to prepend // decimal separator // grouping separator of the integer part // primary grouping size of the integer part //$ (dollar) // string to prepend // decimal separator // grouping separator of the integer part // primary grouping size of the integer part //strReturn = formatValueBR.format(bnStrValueFormated); //strReturn = bnStrValue.toFixed(); //strReturn = bnStrValueFormated; //Decimals. //System currency with decimals. //Check if it´s a decimal. //reduce to just 2 decimal spaces //console.log("bnStrValue (valueMaskRead)=", bnStrValue); //debug //Ajust input number. //Currency. //R$ (Real) // string to prepend // decimal separator // grouping separator of the integer part // primary grouping size of the integer part //$ (dollar) // string to prepend // decimal separator // grouping separator of the integer part // primary grouping size of the integer part //bnStrValue = bnStrValue.toFixed(); //strReturn = bnStrValue; //Debug. //strReturn = strValue; //strReturn = n1.minus(10.1).toFixed(); //strReturn = n1.toFixed(); //strReturn = n1.toFixed(); //working //strReturn = n1.getValue(); //strReturn = bigDecimal(strValue.toString()); //strReturn = BigNumber("'" + strValue + "'"); //strReturn = BigNumber(strValue.toString()); //strReturn = BigNumber(strValue.toString(), 10); //strReturn = BigNumber(strValue.toString()).toFixed(); //strReturn = strValue.toLocaleString('fullwide', {useGrouping:false}); //not working