Link | formatted_decimal |
Author | Kyle Jessup |
Category | Math |
Version | 9.x |
License | Public Domain |
Posted | 07 Oct 2013 |
Updated | 07 Oct 2013 |
More by this author... |
local(one = formatted_decimal(28.456789001)) #one->setFormat(-precision=2) #one->asString // resulting in '28.46'
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define formatted_decimal => type { data public value::decimal, private flags public onCreate(flags = (:)) => { .value = 0.0 .flags = #flags } public onCreate(v::decimal, flags = (:)) => { .value = #v .flags = #flags } public onCreate(v, flags = (:)) => { .value = decimal(#v) .flags = #flags } public setFormat(...rest) => { .flags = #rest } public asString() => .value->asString(:.flags or (:)) public +(rhs::formatted_decimal)::formatted_decimal => formatted_decimal(.value + #rhs->value, .flags) public +(rhs::decimal)::formatted_decimal => formatted_decimal(.value + #rhs, .flags) public +(rhs::integer)::formatted_decimal => formatted_decimal(.value + #rhs, .flags) public -(rhs::formatted_decimal)::formatted_decimal => formatted_decimal(.value - #rhs->value, .flags) public -(rhs::decimal)::formatted_decimal => formatted_decimal(.value - #rhs, .flags) public -(rhs::integer)::formatted_decimal => formatted_decimal(.value - #rhs, .flags) public /(rhs::formatted_decimal)::formatted_decimal => formatted_decimal(.value / #rhs->value, .flags) public /(rhs::decimal)::formatted_decimal => formatted_decimal(.value / #rhs, .flags) public /(rhs::integer)::formatted_decimal => formatted_decimal(.value / #rhs, .flags) public *(rhs::formatted_decimal)::formatted_decimal => formatted_decimal(.value * #rhs->value, .flags) public *(rhs::decimal)::formatted_decimal => formatted_decimal(.value * #rhs, .flags) public *(rhs::integer)::formatted_decimal => formatted_decimal(.value * #rhs, .flags) public onCompare(rhs)::integer => .value->onCompare(#rhs) } define decimal->/(rhs::formatted_decimal) => formatted_decimal(self / #rhs->value) define integer->*(rhs::formatted_decimal) => self * #rhs->value
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft