Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[blockly] Enhance 'round' block to allow setting decimal places #1303

Closed
digitlength opened this issue Feb 7, 2022 · 5 comments · Fixed by #1871
Closed

[blockly] Enhance 'round' block to allow setting decimal places #1303

digitlength opened this issue Feb 7, 2022 · 5 comments · Fixed by #1871
Labels
enhancement New feature or request main ui Main UI

Comments

@digitlength
Copy link

The problem

At the moment the 'round' maths block rounds to the nearest integer.

Your suggestion

Enhance this block to allow setting a user definable number of decimal places. And at least two so that currency values make sense!

Your environment

runtimeInfo:
  version: 3.3.0.M1
  buildString: Milestone Build
locale: en-GB
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.14
  javaVendor: Azul Systems, Inc.
  javaVendorVersion: Zulu11.54+23-CA
  osName: Linux
  osVersion: 5.13.19-2-pve
  osArchitecture: amd64
  availableProcessors: 2
  freeMemory: 170920880
  totalMemory: 314572800
bindings:
  - astro
  - http
  - mqtt

Additional information

@digitlength digitlength added enhancement New feature or request main ui Main UI labels Feb 7, 2022
@digitlength digitlength changed the title [blockly] Enhance Math.round block to allow setting decimal places [blockly] Enhance 'round' block to allow setting decimal places Feb 8, 2022
@florian-h05
Copy link
Contributor

/cc @stefan-hoehn

@stefan-hoehn
Copy link
Contributor

All the math blocks are currently standard math blocks, so I need to reimplement and replace it. Other than that it should be a big topic. I'll put it onto my list a soon as the following PR has been merged:

#1617

@stefan-hoehn
Copy link
Contributor

@digitlength
I have already started to reimplement the block and it seems I can even replace the standard block but there is a catch:
The standard block that does not allow to provide the decimal places has options that generate the following js methods

  • round -> round()
  • round down -> floor()
  • round up -> ceil()

AFAIK there is no way to tell JS to ceil or to floor to a given number of decimal places and round just rounds as necessary. The option we would have is to add a fourth option "toFixed" which behaves as round but with a given number of digits. In that case the block has to mutate its visual representation only then to provide the choice of input for the decimal places.

@florian-h05
@rkoshak

@rkoshak
Copy link

rkoshak commented Jan 23, 2023

Sounds reasonable to me.

@florian-h05
Copy link
Contributor

AFAIK there is no way to tell JS to ceil or to floor to a given number of decimal places and round just rounds as necessary.

I have just checked the mdn web docs and can't find such a method on the Math class, so I guess there is no such method.

The option we would have is to add a fourth option "toFixed" which behaves as round but with a given number of digits. In that case the block has to mutate its visual representation only then to provide the choice of input for the decimal places.

Sounds good 👍

florian-h05 pushed a commit that referenced this issue May 6, 2023
…als (#1871)

Fixes #1303.

Replaces the original math_round block with a new one that adds rounding up, down and by given decimals.

Also-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Stefan Höhn <mail@stefanhoehn.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request main ui Main UI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants