Codes & maths

panyagak

Active Member
Joined
Feb 24, 2017
Messages
299
Hi Mrexcel Greats & Eric W.

Am wondering how to convert a long column with all manner of numbers to a non-zero digit: eg
210.66876468 to 2.1066876468
0.0486788676 to 4.86788676
11.694324507 to 1.1694324507
0.2516033212 to 2.516033212

Thanks
 
=--LEFT(TEXT(A1,"0.00000000000000E+0"),16)

That is 14 zeros after the decimal point.

Bear in mind that there might be more decimal places than you see. For example, 0.0486788676 might be 0.0486788676123456. I presume that your intent is preserve all decimal places.

Also note that the actual original value might be 0.0486788676123456+1.2E-17, but the new value will be just 4.86788676123456. In other words, some unseen infinitesimal precision might be lost.
The only problem I see with your formula are the double minus signs in front.... assuming normat Excel numbers, a floating point number with more than 10 digits will be displayed with only 10 total digits with the last decimal digit being a rounded digit. If you omit the double minus, then all of the digits display (as a text number, of course). Also, here is another formula that will also display the same thing as your formula (with the double minus removed)...

=REPLACE(0+SUBSTITUTE(A1,".",""),2,0,".")

If the value that your original formula is outputs is required, my formulas can do that by adding the double minus sign to it.
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Rick Rothstein

Thank you for your contribution. Will apply all formulas & codes tomorrow & respond aptly.

Regards
 
Upvote 0
Joe4 & thanks for your help.

Referring to your #10 code, suppose I need to select ANY RANGE of cells on which apply the formula, any tweak to your code?

I dont want to mess your code.

Thanks
 
Upvote 0
Joe4 & thanks for your help.

Referring to your #10 code, suppose I need to select ANY RANGE of cells on which apply the formula, any tweak to your code?
This is quite different from the code Joe4 posted for you, but it should return the result you want for a contiguous selection of cells all within a single column...
Code:
[table="width: 500"]
[tr]
	[td]Sub ConvertMacro()
  Selection = Evaluate("IF({1},REPLACE(0+SUBSTITUTE(" & Selection.Address & ",""."",""""),2,0,"".""))")
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
This is quite different from the code Joe4 posted for you, but it should return the result you want for a contiguous selection of cells all within a single column...
Code:
[table="width: 500"]
[tr]
	[td]Sub ConvertMacro()
  Selection = Evaluate("IF({1},REPLACE(0+SUBSTITUTE(" & Selection.Address & ",""."",""""),2,0,"".""))")
End Sub[/td]
[/tr]
[/table]
The restriction I highlighted in red above does not actually apply to the code I posted... you can have a multi-column, multi-row selection and the code will still work as long as the selection is contiguous. One note about the above code... if you have any blank cells within your selection, the code, as written, will return a #VALUE ! error for them. The following modification of the above code will output the empty text string ("") for any blank cells within the selection...
Code:
Sub ConvertMacro()
  Selection = Evaluate("IF(" & Selection.Address & "="""","""",REPLACE(0+SUBSTITUTE(" & Selection.Address & ",""."",""""),2,0,"".""))")
End Sub
 
Upvote 0
Thanks Rick.

Before I test your codes, vmay be my emphasis is "ANY RANGE" NOT a column. Eg. G5:U3400, G2:Y1750......etc

With a column, a formula is straightforward.

May be extra Dims are needed to Joe4's code as opposed to "A1:A": am not sure how to proceed with that....

Regards
 
Upvote 0
Rick, others: (In applying the code in #16)why would Y/X across be OK BUT the Y/X of TOTALS highlighted in GREEN is UNEQUAL
XYY/X
FORMERLATTERFORMER/LATTER
3.6600000003.6600000001OK
0.3743169403.74316939910OK
2.6715328472.6715328471OK
0.6400000006.40000000010OK
7.8593750007.8593750001OK
0.1272365811.27236580510OK
4.3000000004.3000000001OK
1.3186046511.3186046511OK
0.7583774257.58377425010OK
3.1689000003.1689000001OK
6.8911000006.8911000001OK
1.2211000001.2211000001OK
0.1489000001.48900000010OK
1.8611000001.8611000001OK
0.4911000004.91100000010OK
SUM35.49164344358.3510219521.644077768OOPS!!!

<tbody>
</tbody>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,606
Messages
6,125,803
Members
449,261
Latest member
Rachel812321

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