Docly Developers
Function Updated 17 Oct 2026

Math calculations()

Example of doing math calculations within JS.

Numbers are IEEE 754 double-precision values, as in standard JavaScript: 0.1 + 0.2 gives 0.30000000000000004, and 19.90 * 3 gives 59.699999999999996. Round when you display amounts, for example (19.90 * 3).toFixed(2) gives "59.70". When summing money, calculate in whole cents and divide when you display the total. Division by zero gives Infinity, and 0 / 0 gives NaN.

Besides the functions in this section, HashJS supports Math.min, Math.max, Math.trunc, Math.sign, Math.log, Math.log2, Math.log10, Math.exp, Math.cbrt, Math.hypot, Math.asin, Math.acos, Math.atan2, Math.imul and the constant Math.E, as well as Number.isInteger(), Number.isNaN(), Number.EPSILON, Number.MAX_SAFE_INTEGER and (n).toFixed(digits).

Unlike standard JavaScript, Math.abs, Math.floor, Math.ceil and Math.round treat text that is not a number as 0 (not NaN), and accept a comma as decimal separator in numeric text.

Parameters

This function takes no parameters.

Returns

Numbers

Example

Mixed HTML (or any text file) with inline JavaScript between hash signs.
#{
    /* Simple math operations */
    write(5 + 5);
    write(" ");
    write(5 * 5);
    write(" ");
    write(5 - 3);
    write(" ");
    write(5 / 2);
    
    
    write(" ------------ ");
    
    /* More complex */
    write(((5-4) / 2) * 8);
}#