Issue with rounding inside a custom tool

AndeanMath shared this question 3 years ago
Answered

Hi.


I want to create a custom tool to format a number. I am working with the GeoGebra construction shared by @mathmagic in the post:

https://help.geogebra.org/t.... This construction allows to group the digits of an integer number.

I am adding the ability to use different decimal separators, to use different thousand separators, to round to a given number of decimal places, and to work with negative numbers.

The custom tool is FormatNumber(number to format, number of decimal places, decimal separator (text), thousands separator (text))

However, I am facing an issue:

The intermediate object element2 is truncated to two decimal places when the tool works. So, the final tool always truncates the result to two decimal places when the number for rounding is greater than two. Before creating and applying the custom tool, the result has the wanted number of decimal places.

Could you help me to fit the result to the input value for decimals?

Notes:

  1. I know the formulas are no good: there are many objects, several formulas are not efficient.

  2. I have created two intermediate tools to check where is the problem: textFractionalTool and Element2Tool. The arguments of both tools are the number to format and the number of decimal places.

  3. Red objects: unwanted rounding

  4. example objects: outputs of the tools

Best Answer
photo

Extended with negative decimal point.

Comments (6)

photo
2

An alternative solution is attached.

photo
2

Extended with negative decimal point.

photo
1

Hi, rami.

Great. It works very fine. Thanks a lot.

I created the custom tool. It has a very minor issue: when it is used the comma, in LaTeX, is gotten an extra space after it. I will try to solve on the next days.


Attached: the construction, and the custom tool.

photo
photo
2

The intermediate object element2 is truncated to two decimal places

Option 1: set options - rounding


Option 2: you can set the rounding individually for texts, maybe that's helpful

photo
1

Hy, Michael. I tried your suggestion in my first construction: they didn't fix the issue. However, I applied both them to the rami file: there it worked perfectly.

Thanks a lot.

photo
photo
1

Excuse me for the delay to answer. I had a full of work weeks.

© 2023 International GeoGebra Institute