cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Aziza
Level IV

Formatting is not accepted (col << Format( "Fixed Dec", 10, 2 )) and still getting 3 decimal point as the output. What am I doing wrong?

Hello dear community, I am assigning the two decimal point format to a column but when i extract this value it is still showing 3 decimal points. I would appricate your input. Here is an example:
// Open Data Table: Antibiotic MICs.jmp
// → Data Table( "Antibiotic MICs" )
Open( "$SAMPLE_DATA/Antibiotic MICs.jmp" );

// Standardize column attributes-The main idea is the format= Fixed Dec, 10, 2-show two decimal points
Local( {old dt = Current Data Table()},
Current Data Table( Data Table( "Antibiotic MICs" ) );
For Each( {col, index}, {:streptomycin, :neomycin},
col << Format( "Fixed Dec", 10, 2 )
);
Current Data Table( old dt );
);

rowNum = 3; 
colAntib = Column( Data Table( "Antibiotic MICs" ), "neomycin");
//colAntib << Format( "Fixed Dec", 10, 2 );-this also is not working
colAntibVal = colAntib[ rowNum ]; //it is showing 0.007, three decimal points
Greetings
3 REPLIES 3
Anja_W
Level III

Re: Formatting is not accepted (col << Format( "Fixed Dec", 10, 2 )) and still getting 3 decimal point as the output. What am I doing wrong?

Hi Aziza,

 

I would guess that formatting doesn't change the underlying value but just how the value is diplayed in the data table. Because in the data table it actually shows 0.01 for your example.

If you want to access less decimal places in your code, you probably should round your value. 

 

Hope this helps.

 

Aziza
Level IV

Re: Formatting is not accepted (col << Format( "Fixed Dec", 10, 2 )) and still getting 3 decimal point as the output. What am I doing wrong?

Hi Anja, 

 

thank you for your input. 

 

I tried this solution. It works more or less. What is now happening is this

round(0.1964565, 2)
/*:

0.2
Greetings
jthi
Super User

Re: Formatting is not accepted (col << Format( "Fixed Dec", 10, 2 )) and still getting 3 decimal point as the output. What am I doing wrong?

Even if you change the format in the table the values aren't changed. You could round the value after you get it OR you can use << Get Values with Format

Names Default To Here(1);

dt = Open( "$SAMPLE_DATA/Antibiotic MICs.jmp" );

row_nr = 3; 
formatted_values = Column(dt, "neomycin") << Get Values(
	Format( "Fixed Dec", 10, 2 ) /* a numeric column will be list of character items if a format is supplied, see format function */
);

row_val = formatted_values[row_nr];

Do note that this will return you with a string not a number (https://www.jmp.com/support/help/en/17.0/#page/jmp/date-and-time-functions.shtml?os=win&source=appli...). You can convert it into a number using Num()

 

-Jarmo