Skip to content

Instantly share code, notes, and snippets.

@yyamasak
Last active November 1, 2016 08:11
Show Gist options
  • Save yyamasak/50430fab7f8c34099c1b302ae2a8033f to your computer and use it in GitHub Desktop.
Save yyamasak/50430fab7f8c34099c1b302ae2a8033f to your computer and use it in GitHub Desktop.
Rounding in decimal arithmetic
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