convert text format to number

mwb

Board Regular
Joined
Sep 3, 2004
Messages
88
I am trying to convert existing data from text to number format. the cells contain numbers and text ((123.100grams). The text is always different as is the number of decimal places that need to be retained. Is there a way to pull the number of entered decimal places (i.e. 123.100 = 3) from this string? the Val function will return 123.1 but I loose the displayed decimals if I rewrite the cell Val after changing the format to number. I think I can calculate it by finding the position of the decimal, then finding the position of the last number... not sure how to find the last number though.

Cheers!
 
=--"1" produces 1

You can think of it as...

=-(-("1"))

Duel unary minus (-) operators can be used to coerce a text value into a numeric one.

In fact, any arithmetic operator can be used for this coercion; however, if one uses a binary operator (e.g., +, *) it's best to use it in conjunction with the operation's identity element (0 and 1 respectively).

For example,

="1"+0 produces 1
="2"*1 produces 2

Barry's formulation is using coercion to change the text characters produced by the MID function into numeric values so that he can use an approximate MATCH to find the last numeric value in the string. This nifty approach works because 10 is larger than any single digit number.
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,215,532
Messages
6,125,367
Members
449,221
Latest member
chriscavsib

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top