close Warning: Can't synchronize with repository "(default)" (/var/svn/tolp does not appear to be a Subversion repository.). Look in the Trac log for more information.

Opened 21 years ago

Closed 18 years ago

#19 closed enhancement (fixed)

Round function and decimal number

Reported by: manuelb Owned by: Víctor de Buen Remiro
Priority: normal Milestone:
Component: Math Version: head
Severity: minor Keywords:
Cc:

Description

From the old TOL forums:

Hi.
I think the Round function should have a second argument (optional) that indicates the
number of decimals you want it to round the number to, defaulting to zero.

Now the function is defined:

Real Round(Real r)

--> Real Round(4.8369) = 5;

I propose:

Real Round(Real x [, Real p=0]):
--> Real Round(4.8369) = 5;
--> Real Round(4.8369, 2) = 4.84;

Regards.

Change History (7)

comment:1 Changed 21 years ago by danirus

Status: newassigned

comment:2 Changed 21 years ago by rcsoto

Since C++ does not implement the Round() with two parameters, the mechanism
can be used that is used at the moment in tol.
If "p" is distinct from zero:

Round(n*10p) / (10p)

Example:

Real n = 1234.56789;
Real p1 = 2;
Real p2 = -2;

Real r1 = (Round(n*10p1)) / (10p1);
Real r2 = (Round(n*10p2)) / (10p2);

I hope that it serves as help.

comment:3 Changed 21 years ago by danirus

Resolution: fixed
Status: assignedclosed

Implementd the enhancement proposed by Ivan consistent in provide a second argument to
Round function of Real type, telling that the result must have a number of decimal digits
instead of return an integer.
This new argument is optional.

comment:4 Changed 18 years ago by Víctor de Buen Remiro

bug_file_loc: http://cvs.tol-project.org/viewcvs.cgi/tol_tests/tol/Bugzilla/bug_000019
Resolution: fixed
Status: closedreopened

In next code

Real n = 14.8369;
Real p1 = 1;
Real p2 = -1;
Real r1 = (Round(n*10p1)) / (10p1);
Real r2 = (Round(n*10p2)) / (10p2);
Real r1_= Round(n,p1);
Real r2_= Round(n,p2);

r1 is equal to r1 and r2_ should be equal to r2 but it is not happens thus.

comment:5 Changed 18 years ago by Víctor de Buen Remiro

The correct value is r2 = 10, not r2_=14.8369
It's to say the number of decimals should be extended with negative values in the same way that positive ones to round a value to decenes, hundreds, etc.

comment:6 Changed 18 years ago by Víctor de Buen Remiro

Owner: changed from danirus to Víctor de Buen Remiro
Status: reopenednew

comment:7 Changed 18 years ago by Víctor de Buen Remiro

Resolution: fixed
Status: newclosed

Problem has been solved in CVS

Note: See TracTickets for help on using tickets.