From WikiChip
Difference between revisions of "mirc/identifiers/$round"
(→Paramters) |
Maroonbells (talk | contribs) (Add'l examples) |
||
Line 5: | Line 5: | ||
<pre>$round(N,D)</pre> | <pre>$round(N,D)</pre> | ||
− | == | + | == Parameters == |
* '''N''' - The number you want to round, can be negative. | * '''N''' - The number you want to round, can be negative. | ||
− | * '''D''' - The number of decimal to round | + | * '''D''' - The number of decimal to round. This parameter is optional, but appears to not alter the number otherwise returned by $calc(). |
+ | * Note: mIRC's floating point accuracy is currently at 6 places, so D has no effect outside the range 0-6. | ||
+ | * Note: Rounding to D fractional digits can show fewer than D digits because it does not pad trailing zeroes. | ||
== Properties == | == Properties == | ||
None | None | ||
== Example == | == Example == | ||
− | <source lang="mIRC">//echo -a $round(4.98472,3)</source> | + | <source lang="mIRC"> |
+ | //echo -a $round(4.98472,3) | ||
+ | |||
+ | Even though $pi has 20 decimal places, all results limited to 6 places. Note that $calc also rounds to 6 places: | ||
+ | //echo -a $pi calc: $calc($pi) round: $round($pi,7) | ||
+ | result: 3.14159265358979323846 calc: 3.141593 round: 3.141593 | ||
+ | |||
+ | Because of floating point translation to/from base 10, the result is not always the fraction expected: | ||
+ | //var %i 1 , %list | while (%i isnum 1-100) { var %list %list $round(%i $+ .05 ,1) | inc %i } | echo -a round: %list | ||
+ | result: round: 1.1 2 3 4 5 6 7 8.1 9.1 10.1 11.1 12.1 13.1 14.1 15.1 16.1 17.1 18.1 19.1 20.1 21.1 22.1 23.1 24.1 25.1 26.1 27.1 28.1 29.1 30.1 31.1 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | ||
+ | </source> | ||
== Compatibility == | == Compatibility == | ||
Line 20: | Line 32: | ||
== See Also == | == See Also == | ||
− | {{mIRC|$int}} | + | * {{mIRC|$int}} |
− | {{mIRC|$ceil}} | + | * {{mIRC|$ceil}} |
− | {{mIRC|$floor}} | + | * {{mIRC|$floor}} |
− | + | * {{mIRC|$abs}} | |
− | {{mIRC|$abs}} | + | * {{mIRC|$calc}} |
− | {{mIRC|$calc}} | ||
− |
Revision as of 03:44, 30 April 2018
Commands & Identifiers
Basics
Events
Matching Tools
Data Storage
Control Structures
GUI Scripting
Sockets
Advanced Scripting
Additional Resources
Security
Other
$round returns a floating point number rounded to a number of decimal.
Synopsis
$round(N,D)
Parameters
- N - The number you want to round, can be negative.
- D - The number of decimal to round. This parameter is optional, but appears to not alter the number otherwise returned by $calc().
- Note: mIRC's floating point accuracy is currently at 6 places, so D has no effect outside the range 0-6.
- Note: Rounding to D fractional digits can show fewer than D digits because it does not pad trailing zeroes.
Properties
None
Example
//echo -a $round(4.98472,3) Even though $pi has 20 decimal places, all results limited to 6 places. Note that $calc also rounds to 6 places: //echo -a $pi calc: $calc($pi) round: $round($pi,7) result: 3.14159265358979323846 calc: 3.141593 round: 3.141593 Because of floating point translation to/from base 10, the result is not always the fraction expected: //var %i 1 , %list | while (%i isnum 1-100) { var %list %list $round(%i $+ .05 ,1) | inc %i } | echo -a round: %list result: round: 1.1 2 3 4 5 6 7 8.1 9.1 10.1 11.1 12.1 13.1 14.1 15.1 16.1 17.1 18.1 19.1 20.1 21.1 22.1 23.1 24.1 25.1 26.1 27.1 28.1 29.1 30.1 31.1 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Compatibility
Added: mIRC v5.1
Added on: 28 Aug 1997
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.