|
Operating with decimals Anonymous |
11 year
|
Hello.
I can not do the program well to add a decimal integer.
I have a variable "distance" made with two points with the module "display_line". When the program runs this variable gives me incremental values as 6.355 / 6.489 / 6.590 / 6.654 ............
I would like to add the difference in decimal value of each for a total distance "Total distance". Eg
(6.489 to 6.355) = 0.134
(6.590 to 6.489) = 0.101
(6.654 to 6.590) = 0.064
Therefore, the total distance "Total distance" is 0.134 + 0.101 + 0.064 = 0.299 m.
This is the part of my VBScript program where I try to figure this.
i = GetVariable("distance")
decimal=Mid(CStr(3/2), 2, 1)
i=CDbl(Replace(CStr(i),",",decimal))
add=i+i
SetVariable "Total disatance",add
Thanks so much.
|
|
|
Steven Gentner from United States [1446 posts] |
11 year
|
I'm not sure that will get you want you are asking for. If you are trying to convert a comma into a period due to your international usage you may just want to change the
Windows Start Button->Control Panel->Region and Language->Additional Settings->Change Decimal Symbol to a period.
If you want to add the changes from the distance you start with a set base number and then check the difference to that number as apposed to adding each time it changes ... something like:
if GetVariable("Start_Distance") = 0 then
SetVariable "Start_Distance", GetVariable("distance")
end if
SetVariable "Total_Distance", GetVariable("distance") - GetVariable("Start_Distance")
and that should do it.
STeven.
|
|
|
Anonymous |
11 year
|
Hi Steven.
For example, number 4,589
I need a function in VBscript I separate the decimal integer. I need this decimal 0,589.
|
|
|
Steven Gentner from United States [1446 posts] |
11 year
|
result = 4.589 - CInt(4.589)
should do that.
STeven.
|
|