1. ## Rounding a number

User (yan.chan@fmr.com) posted:

Hi Does anyone know how to round up/down a value.

a = 4.5235
I need it to round up to 4.524.

Yan

2. ## Re: Rounding a number

------_=_NextPart_001_01C0EDE7.9277D8D0
Content-Type: text/plain;
charset="iso-8859-1"

That's not really a round number, integers are round numbers, but I guess
that's semantics... You could break the number into string parts, do
whatever math on them you need to then join them together again.

a = "4.5235";

split(a,Arr,".")
a1 = Arr[1];
a2 = Arr[2];

while ( substr(a2,length(a2) ) != 0 )
a2++;

a = a1 & "." & a2;
a = a + 0;

3. ## Re: Rounding a number

User (JSchwartz@DTCC.com) posted:

Try this......

################################################## ###############
# This function returns the inputted number rounded to the
# requested number of decimal places.
# Until WinRunner can do BCD math, string functionality is used.
################################################## ###############
public function round (num, place) {
return sprintf ("%."place"f", num);
}

Credits to my friend, Sumanta.

Jerry S.

4. ## Re: Rounding a number

a = 4.5235 ;
a = int((a * 1000) + 0.5) / 1000 ;

------------------
Charles Reace

Software Testing (n): 1. The art of trying to increase your confidence in a piece of software by finding everything that is wrong with it.

5. ## Re: Rounding a number

This code looks at the Big picture...

It handles number of decimal places and rounds Up and Down.

See attached text file.

This code is ugly and un-tested...

------------------

6. ## Re: Rounding a number

Function to perform a simple round on a number in WinRunner.
Number is number to round, and NbrOfDigits is the number of places after the decimal at which to round.

static function f_Round(inout Number, in NbrOfDigits)
{
Number = (int( (Number + ( .5 / (10 ^ NbrOfDigits) ) ) * (10 ^ NbrOfDigits) )) / (10 ^ NbrOfDigits);
}

------------------

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.