| ||||||||||
How function can returns floating-point values Posted by triclosan (triclosan), 20 July 2005 For example: Code:
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. Code:
If you can be certain that one of your input variables is an integer, you can just add a "." in the code: Code:
Posted by triclosan (triclosan), 21 July 2005 on 07/21/05 at 06:09:56, Graham Ellis wrote:
This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |