18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
adding values with decimal or float..
Hi,
when i tried this one:
var $value = 1.2;
for (var $ctr=0; $ctr <= 4; $ctr++){
_setValue(_textbox("txt_value"), $value);
$value = $value + 0.1;
}
i got these results for $value:
1.2
1.3
1.4000000000000001
1.5000000000000002
.... how do i make 1.4000000000000001 and 1.5000000000000002 to be just 1.4 and 1.5??
in C we got this %.2f, but in SAHI i dont know how to do this.....
Anyone know how??
would greatly appreciate your help...
Thanks
=Tinchie=
when i tried this one:
var $value = 1.2;
for (var $ctr=0; $ctr <= 4; $ctr++){
_setValue(_textbox("txt_value"), $value);
$value = $value + 0.1;
}
i got these results for $value:
1.2
1.3
1.4000000000000001
1.5000000000000002
.... how do i make 1.4000000000000001 and 1.5000000000000002 to be just 1.4 and 1.5??
in C we got this %.2f, but in SAHI i dont know how to do this.....
Anyone know how??
would greatly appreciate your help...
Thanks
=Tinchie=
Comments
If its always like you have one digit to left of the decimal place then use
$value = Math.round($value*100)/100;
Regards,
Pankaj.
http://www.pageresource.com/jscript/j_a_03.htm
both pankaj and your suggestion worked!