06-06-2020, 03:58 +0200
AuthorPost
clrsrc  05-22-2014, 12:33   | adding two variables  shows wrong result
Member since 05/2014
2 Posts
Location: Willich
Hallo Everyone,

want to increase the value of variable a with variable b , the result should be
stored in variable a , nothing very special.

the first result is 1.1 , as expected
the second result is 1.2000000000000002 , expected 1.2

Does anyone has got an idea ?

set a 1.0
set b 0.1

set a [expr $a + $b]
set a [expr $a + $b]

puts "Soll 1.2 , ist : $a"

Printout :

Soll 1.2 , ist : 1.2000000000000002

Best regards

Stefan
CyBex  05-22-2014, 16:40   Jabber  ICQ  AOL IM  Yahoo IM  MSN  Homepage
nie da
(Administrator)

Avatar

Member since 01/2004
260 Posts
Location: Berlin
tclsh8.5 [~]set tcl_precision 5 ; # (anzahl stellen wieviel genau sein soll)
5
tclsh8.5 [~]set a 1.0
1.0
tclsh8.5 [~]set b 0.1
0.1
tclsh8.5 [~]set a [expr {$a + $b}]
1.1
tclsh8.5 [~]set a [expr {$a + $b}]
1.2

http://tclhelp.net/tcl/expr.htm#M23

mfG CyBex @ QuakeNet, UnderNet, EFNet, Freenode, euIRC, GameSurge & ShadowWorld - Files
clrsrc  05-22-2014, 19:57   | Danke
Member since 05/2014
2 Posts
Location: Willich
klappt perfekt
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen | Time: 153.8 msec, CPU time: 70.6 msec, 35 Database queries in 114 msec | 3.3 kB (13.5 kB) | Timezone: +0200