<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Convert to nearest whole number - No Rounding in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/363557#M61314</link>
    <description>&lt;P&gt;You can use Floor() and Ceiling() functions.&lt;/P&gt;</description>
    <pubDate>Sat, 27 Feb 2021 02:30:27 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2021-02-27T02:30:27Z</dc:date>
    <item>
      <title>Convert to nearest whole number - No Rounding</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/363549#M61312</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Being new to JMP, I'm sure this is a typical beginner's mistake.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to convert a decimal number to a whole number without rounding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried using Round(x, 0),&amp;nbsp;but the number is always rounded up.&lt;/P&gt;&lt;P&gt;I've also tried formatting the value from column1,&amp;nbsp; and converting back to a number (fails).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Column1 is defined:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Column( "Time",
		Numeric,
		Continuous,
		Format( Best, 12),
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Column2 is defined:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Column( "WholeSeconds",
		Numeric,
		Continuous,
		Format( Fixed Dec, 5, 0),
	);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each Row( 
	lvTime = dt:Time;
	dt:WholeSeconds = Round( lvTime,0);
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:07:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/363549#M61312</guid>
      <dc:creator>swanthog</dc:creator>
      <dc:date>2023-06-09T22:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to nearest whole number - No Rounding</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/363557#M61314</link>
      <description>&lt;P&gt;You can use Floor() and Ceiling() functions.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 02:30:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/363557#M61314</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-02-27T02:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to nearest whole number - No Rounding</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/363592#M61316</link>
      <description>&lt;P&gt;In addition to&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;, here's the code for it:&lt;/P&gt;&lt;P&gt;As you can see, you can uses a formula, or written values to that column.&lt;BR /&gt;It's better to avoid loops (for each row), if tables can do it without, if possible.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 ) ) )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Georg_0-1614420933166.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/30809i53C7BA02262E56F5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Georg_0-1614420933166.png" alt="Georg_0-1614420933166.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 10:17:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/363592#M61316</guid>
      <dc:creator>Georg</dc:creator>
      <dc:date>2021-02-27T10:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to nearest whole number - No Rounding</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/363820#M61348</link>
      <description>&lt;P&gt;Thank you, Georg, and txnelson.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate the name resolution tip too. I hadn't come across it yet in the documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Lawrence&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 14:24:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/363820#M61348</guid>
      <dc:creator>swanthog</dc:creator>
      <dc:date>2021-03-01T14:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to nearest whole number - No Rounding</title>
      <link>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/364268#M61385</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11980"&gt;@swanthog&lt;/a&gt;, in a script I tested out three different methods for calculating a square y = x*x in a table with different number of rows.&lt;/P&gt;&lt;P&gt;The outcome is,&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;that the loop takes ten times more time&lt;/LI&gt;&lt;LI&gt;as the table operation&lt;/LI&gt;&lt;LI&gt;and the matrix calculation is 5x faster than the table operation&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But for small scripts, and if performance is no issue, loops are also ok. Also readability (to the eyes of the writer) counts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Georg_0-1614669857895.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/30872i1BBDFFFA0B4456EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Georg_0-1614669857895.png" alt="Georg_0-1614669857895.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 07:35:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Convert-to-nearest-whole-number-No-Rounding/m-p/364268#M61385</guid>
      <dc:creator>Georg</dc:creator>
      <dc:date>2021-03-02T07:35:07Z</dc:date>
    </item>
  </channel>
</rss>

