openmolecules.org

 
Home » DataWarrior » Functionality » Round numbers by decimal places?
Round numbers by decimal places? [message #2445] Wed, 19 November 2025 22:23 Go to next message
Santora V is currently offline  Santora V
Messages: 8
Registered: March 2024
Junior Member
Is there a simple way to round numbers by decimal places rather than significant figures? I have a column with values that range from 1 to several digits (first list below), and I want to round them as shown in the 2nd list.

Perhaps a find and replace search?

Thanks!

1.1
11.2
11.6
101.2
101.6

Round to:
1
11
12
101
102
Re: Round numbers by decimal places? [message #2446 is a reply to message #2445] Thu, 20 November 2025 13:39 Go to previous messageGo to next message
amorrison
Messages: 39
Registered: March 2016
Member
Hi,

If you don't mind an extra column you can use "Add Calculated Values" to round numbers.

Rounded Value - round(x, scale).

Best,

Angus
Re: Round numbers by decimal places? [message #2447 is a reply to message #2446] Fri, 21 November 2025 02:04 Go to previous messageGo to next message
Santora V is currently offline  Santora V
Messages: 8
Registered: March 2024
Junior Member
Thanks, Angus.

I'm aware of this option, but would like to include the change in a macro for any/all columns rather than create multiple calculated columns.
Re: Round numbers by decimal places? [message #2455 is a reply to message #2447] Sun, 07 December 2025 12:46 Go to previous message
nbehrnd is currently offline  nbehrnd
Messages: 235
Registered: June 2019
Senior Member
Hello Santora

As an example for a small set of 10 molecules, the dwam macro attached proceeds in a sequence to

- compute the molecular weight, like one would click over Chemistry -> From Chemical Structure -> Calculate Propeties -> Total average molweight, to create a temporary new column. DW 06.0.5.02 populates this one with three decimals if the third one is 1-9, a 0 leads to truncation
- creates a new column `MW_rounded` of calculated values (here: to round the molecular weight to 0 decimals)
- deletes the earlier, now no longer needed column of molecular weights with up to 3 decimals.

The .dwam is the result of recording the macro (macro -> start recording, later macro -> end recording and export macro). In the step to create the column about rounded molecular weights, during recording the macro, one can opt-in to directly overwrite the already existing column about molecular weight, too (see the second macro). This simplifies the macro file; using one, or the other route depends on your preferences.

Best regards

Norwid
Previous Topic: Security feature
Goto Forum:
  


Current Time: Sun Dec 14 20:35:24 CET 2025

Total time taken to generate the page: 0.61796 seconds