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
Status: | new → assigned |
---|
comment:2 Changed 21 years ago by
comment:3 Changed 21 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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
bug_file_loc: | → http://cvs.tol-project.org/viewcvs.cgi/tol_tests/tol/Bugzilla/bug_000019 |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
comment:5 Changed 18 years ago by
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
Owner: | changed from danirus to Víctor de Buen Remiro |
---|---|
Status: | reopened → new |
comment:7 Changed 18 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Problem has been solved in CVS
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:
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.