diginext-utils
Version:
README.md
29 lines • 728 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toFloat = toFloat;
const isNull_1 = require("./isNull");
/**
* Converts a value to a floating-point number.
* Returns 0 if the value cannot be converted.
*
* @param value - The value to convert
* @returns The floating-point representation
*
* @example
* ```ts
* toFloat('3.14'); // 3.14
* toFloat('42'); // 42
* toFloat(5.7); // 5.7
* toFloat('hello'); // 0
* toFloat(null); // 0
* toFloat(''); // 0
* ```
*/
function toFloat(value) {
if ((0, isNull_1.isNull)(value)) {
return 0;
}
const result = parseFloat(String(value));
return Number.isNaN(result) ? 0 : result;
}
//# sourceMappingURL=toFloat.js.map