简体   繁体   中英

Rounding in Tcl

How can I round off a decimal number to the nearest integer in Tcl?

For example, if I enter

  • 12.34 as input, the desired output is 12
  • 12.45 as input, the desired output is 12
  • 12.50 as input, the desired output is 13
  • 12.57 as input, the desired output is 13

and so on

Take a look at the documentation for the expr command and for the round function.

Basically, it's

expr {round($myNum)}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM