Flags & Debug
enableDecimals
$enableDecimals
The $enableDecimals[] function enables or disables decimal display in calculations for the current command.
Syntax
$enableDecimals[enable]
Parameters
| Parameter | Description |
|---|---|
enable |
Required (exactly one argument). yes, true, on or enable to enable decimals; no, false, off or disable to disable them. Any other value raises “Expected an enable-decimals boolean.”. A bare $enableDecimals is refused (“Invalid argument count”). |
Return value
An empty string.
Behavior
- Without it (default: disabled), the non-integer results of
$calculate[],$sum[],$sub[],$multi[],$divide[]and$sqrt[]are rounded to the nearest integer (halves round up:2.5gives3,-2.5gives-2), and$randomwithout arguments returns an integer from 0 to 9. - With
$enableDecimals[yes], the results keep their decimals (and$randomwithout arguments returns a decimal between 0 and 10). $enableDecimals[no]turns it off again.- The effect is limited to the current command.
Examples
Calculation with decimals
$enableDecimals[yes]
$sendMessage[10 ÷ 3 = $calculate[10/3]]
; Displays: 10 ÷ 3 = 3.3333333333333335
Without decimals (default)
$sendMessage[10 ÷ 3 = $calculate[10/3]]
; Displays: 10 ÷ 3 = 3
Comparison before/after
$var[without;$calculate[10/3]]
$enableDecimals[yes]
$var[with;$calculate[10/3]]
$sendMessage[Without: $var[without] | With: $var[with]]
Notes
- Place before the calculations concerned.
- To round a calculation to N decimals, enable decimals first and then use
$round[$calculate[...];N]: without$enableDecimals[yes],$calculatehas already rounded its result to an integer ($round[$calculate[10/3];2]gives3, whereas$round[2.567;2]gives2.57in any case). - The
enableargument is required: use$enableDecimals[yes].
Try it
Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.