Blog

PHP

function number_format_to_decimal(?string $value)
{
    if (is_null($value)) {
        return null;
    }

}


JavaScript
function number_format_to_decimal(value)
{	
    var decimal = "0.00";
    var count_comma_seperators = 0;
    var count_dot_seperators = 0;
    if (value.indexOf(",") != "-1") {
        count_comma_seperators += value.split(",").length - 1;
    }
    if (value.indexOf(".") != "-1") {
        count_dot_seperators += value.split(".").length - 1;
    }
    if (count_comma_seperators == 1 && count_dot_seperators == 0) {
        let count_decimals = value.split(",")[1].length;
        if (count_decimals == 3) {
            decimal = value.replace(",", "");
        } else {
            decimal = value.replace(",", ".");
        }
    } else if (count_comma_seperators == 0 && count_dot_seperators == 1) {
        let count_decimals = value.split(".")[1].length;
        if (count_decimals == 3) {
            decimal = value.replace(".", "");
        } else {
            decimal = value;
        }
    } else if (count_comma_seperators == 1 && count_dot_seperators == 1) {
        decimal = value.replace(",", ".");
        decimal = decimal.replace(/[.](?![^.]*$)/, "");
    } else if (count_comma_seperators == 0 && count_dot_seperators > 1) {
        decimal = value.replace(/\./g, "");
    } else if (count_comma_seperators > 1 && count_dot_seperators == 0) {
        decimal = value.replace(/\,/g, "");
    } else if (count_comma_seperators == 1 && count_dot_seperators > 1) {
        decimal = value.replace(/\./g, "");
        decimal = decimal.replace(/\,/g, ".");
    } else if (count_comma_seperators > 1 && count_dot_seperators == 1) {
        decimal = value.replace(/\,/g, "");
    } else {
        decimal = value;
    }
    return decimal;
}
Zoeken