How function can returns floating-point values
Posted by triclosan (triclosan), 20 July 2005For example:
Function 'funct' returns '3'. How i can get floating-point value?
Posted by admin (Graham Ellis), 20 July 2005By doing a floating point operation rather than an integer one.
(note the extra "." after the 10)
Posted by triclosan (triclosan), 20 July 2005Thnx 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 2005In 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.
If you can be certain that one of your input variables is an integer, you can just add a "." in the code:
Posted by triclosan (triclosan), 21 July 2005on 07/21/05 at 06:09:56, Graham Ellis wrote:
Other Forum Posts
Follow us on ...
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho