possibly useful trick

C

Carl Witthoft

On the off chance that not everybody (besides me :) ) knows this:

I had a csv file with a several columns of data and a column of text
identifying each row. The identifiers were things like "sample1,"
"sample2," and so on; with many rows belonging to a given sampleX value.

I created a column which extracted the number, using RIGHT(), and found
out that Excel treated the extracted value as a string aka text format.
This was not too surprising. The cool thing is that if I wrote a
formula like

=RIGHT(A1,1)*1

Then the value in the cell was converted to numeric, and I could do
other 'stuff' with it.

neat, huh?
 
B

Bob Greenblatt

On the off chance that not everybody (besides me :) ) knows this:

I had a csv file with a several columns of data and a column of text
identifying each row. The identifiers were things like "sample1,"
"sample2," and so on; with many rows belonging to a given sampleX value.

I created a column which extracted the number, using RIGHT(), and found
out that Excel treated the extracted value as a string aka text format.
This was not too surprising. The cool thing is that if I wrote a
formula like

=RIGHT(A1,1)*1

Then the value in the cell was converted to numeric, and I could do
other 'stuff' with it.

neat, huh?
Yup, RIGHT, LEFT, MID, etc. all produce string results. Multiplying by 1,
adding or subtracting 0, dividing by 1, etc. are all techniques that coerce
the string to a value.
 
J

JE McGimpsey

Bob Greenblatt said:
Yup, RIGHT, LEFT, MID, etc. all produce string results. Multiplying by 1,
adding or subtracting 0, dividing by 1, etc. are all techniques that coerce
the string to a value.

And just because it's, rather unaccountably, a pet peeve: using two
unary minus operators,

--LEFT(A1,1)

is, on a percentage basis, significantly more efficient than using any
binary operator (*, /, +, -).

However, unless you're iterating millions of times, you shouldn't waste
those nanoseconds by blinking...<g>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top