Last active
November 1, 2016 08:11
-
-
Save yyamasak/50430fab7f8c34099c1b302ae2a8033f to your computer and use it in GitHub Desktop.
Rounding in decimal arithmetic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package require math::decimal | |
math::decimal::setVariable extended 0 | |
proc tcl::mathfunc::roundto {value sigfig dp} { | |
math::decimal::setVariable precision $sigfig | |
set d_val [math::decimal::fromstr $value] | |
set d_rou [math::decimal::round_half_up $d_val 100] | |
set d_rou [math::decimal::round_floor $d_rou $dp] | |
math::decimal::tostr $d_rou | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment