Convert to nearest whole number - No RoundingHi.
Being new to JMP, I'm sure this is a typical beginner's mistake.
I need to convert a decimal number to a whole number without rounding.
Example 1: The value 0.5986 is copied from column1 and saved to column2. 0 should be saved to column2. Instead 1 is being saved.
Example 2: The value 1.5986 is copied from column1 and saved to column2. 1 should be saved to column2. Instead 2 is being saved.
I've tried using Round(x, 0), but the number is always rounded up.
I've also tried formatting the value from column1, and converting back to a number (fails).
Column1 is defined:
New Column( "Time",
Numeric,
Continuous,
Format( Best, 12),
);
Column2 is defined:
New Column( "WholeSeconds",
Numeric,
Continuous,
Format( Fixed Dec, 5, 0),
);
Code:
For Each Row(
lvTime = dt:Time;
dt:WholeSeconds = Round( lvTime,0);
);
Any help is greatly appreciated.
Thank you.
Content OrganizationData AccessData Blending and CleanupMass CustomizationQuality and Process EngineeringSharing and Communicating ResultsRe: Convert to nearest whole number - No RoundingDear @swanthog, in a script I tested out three different methods for calculating a square y = x*x in a table with different number of rows.
The outcome is,
- that the loop takes ten times more time
- as the table operation
- and the matrix calculation is 5x faster than the table operation
Also in terms of clean code and less errors, it is in my opinion a good recommendation to avoid loops, if there are other methods (table and matrix), that have built in functionality to adress each element.
But for small scripts, and if performance is no issue, loops are also ok. Also readability (to the eyes of the writer) counts.

Re: Convert to nearest whole number - No RoundingThank you, Georg, and txnelson.
I appreciate the name resolution tip too. I hadn't come across it yet in the documentation.
I'm guessing the recommendation for avoiding loops is due to negative performance impact. Is that right? What (roughly) is the impact/difference to performance using loops vs table formulas?
Thanks!
Lawrence
Re: Convert to nearest whole number - No RoundingIn addition to @txnelson , here's the code for it:
As you can see, you can uses a formula, or written values to that column.
It's better to avoid loops (for each row), if tables can do it without, if possible.
Names Default To Here( 1 );
cdt = New Table( "Example Floor",
add rows( 2 ),
New Column( "Time", Numeric, Continuous, Format( Best, 12 ), set values( [0.5986, 1.5986] ) ),
New Column( "WholeSeconds_formula", Numeric, Continuous, Format( Best, 12 ), Formula( Floor( :Time ) ) ),
New Column( "WholeSeconds_value", Numeric, Continuous, Format( Best, 12 ), set each value( Floor( :Time ) ) )
);

Re: Convert to nearest whole number - No RoundingYou can use Floor() and Ceiling() functions.