Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems

Phone System reconfiguration 11.1.2018 and 12.1.2018 - we are on email but incoming phone not available all the time
How function can returns floating-point values

Posted by triclosan (triclosan), 20 July 2005
For example:
proc funct {} {
return [expr 10/3]      

Function 'funct' returns '3'. How i can get floating-point value?

Posted by admin (Graham Ellis), 20 July 2005
By doing a floating point operation rather than an integer one.

For example

expr 10./3

(note the extra "." after the 10)

Posted by triclosan (triclosan), 20 July 2005
Thnx for answer!

But it's so inconveniently. For example I write plugin for some software on Tcl/Tk and it software application sends to Tcl value '10'. How I do convert it to '10.'  ?

Posted by admin (Graham Ellis), 21 July 2005
In most circumstances, the way Tcl does it is very clever and elegant - you do a division using floating point numbers and it does a floating point division ... give it integers and it knows to do an integer division.

If you want to divide an integer by an integer using a floating point division, you need to convert at least one of them. Personally, I often multiply by 1.0 or add 0.0 before dividing as that will work no matter what type of number the input variables are.

set tom 10
set fred 3
set result [expr 1.0 * $tom / $fred]

If you can be certain that one of your input variables is an integer, you can just add a "." in the code:

set tom 10
set fred 3
set result [expr $tom / $fred.]

Posted by triclosan (triclosan), 21 July 2005
on 07/21/05 at 06:09:56, Graham Ellis wrote:
I often multiply by 1.0 or add 0.0 before dividing

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho