import { assert } from "../../assert.js";

/**
 *
 * @param {number} value
 * @returns {number}
 */
export function number_count_decimals(value) {
    assert.isNumber(value, 'value');

    if (value % 1 === 0) {
        //whole number
        return 0;
    }

    const s = value.toString();
    const index = s.indexOf('.');

    if (index === -1) {
        return 0;
    }

    //find last 0
    let endIndex = s.length - 1;
    for (; endIndex > index && s.charAt(endIndex) === "0"; endIndex--) {

    }

    return endIndex - index;
}