Show Decimals until first non-zero decimal is shown

quauq

New Member
Joined
Oct 8, 2024
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi all,

i have a sheet with various numbers of market shares in column A (e.g. 2.2%, 5%). Some of those shares can also be <1 (e.g. 0.0092%, 0.045, 0.033% etc.).

I need to copy those values into a Word-document. However, the values displayed in the Word-doc should only ever show decimals until the first non-zero decimal is displayed (with a minimum of 1 decimal being shown). Normally, I use "Increase Decimal" and "Decrease Decimal" under the Number options. That way, in the examples I listed, 0.0092% would show as 0.01%, 0.045 would show as 0.05 (as with the way I described, Excel rounds dynamically) and 0.033% would show as 0.03%.

Is there a formula (or some other way) to automate this task in column B, so I need only copy those results into my Word-doc?

The formula I could come up with, does not do the trick (the rounded values are incorrect), but the idea should be in there somewhere:

=IFERROR(IF(A4*100>1;ROUND(A4*100;1);IF(RIGHT(100*ROUND(A4;INT(1-LOG(A4)));1)>=5;100*ROUND(A4;INT(1-LOG(A4))-1);100*ROUND(A4;INT(1-LOG(A4;10))))&"%");"n.a.")

Thank you!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this

Book1
AB
1
2
3
40.60%0.6%
50.045%0.05%
60.033%0.03%
755.60%55.6%
81.12%1.12%
90.0092%0.01%
Sheet2
Cell Formulas
RangeFormula
B4:B9B4=TEXT(A4,INDEX({"0%","0.0%","0.00%"},MATCH(TRUE,MOD(A4*1000000000,{10000000,1000000,1})=0,0)))
 
Upvote 0
Try this

Book1
AB
1
2
3
40.60%0.6%
50.045%0.05%
60.033%0.03%
755.60%55.6%
81.12%1.12%
90.0092%0.01%
Sheet2
Cell Formulas
RangeFormula
B4:B9B4=TEXT(A4,INDEX({"0%","0.0%","0.00%"},MATCH(TRUE,MOD(A4*1000000000,{10000000,1000000,1})=0,0)))
Thank you!

this formula does indeed work fine for the values provided. However, I tried adapting it to very small values and for some reason it does not round correctly anymore.

=TEXT(B12;INDEX({"0%";"0,0%";"0,00%";"0,000%";"0,0000%";"0,00000%";"0,000000%";"0,0000000%";"0,00000000%";"0,000000000%"};MATCH(TRUE;MOD(B12*1000000000;{10000000;1000000;100000;10000;1000;100;10;1})=0;0)))

With this formula 0,000000005 becomes 0,0000005%, which is correct as far as decimal to % goes, but it should be 0,00000001% if rounded correctly.
 
Upvote 0
Could you provide a small sample of conversion you need to obtain? An image would be enough, an XL2BB table would be better
 
Upvote 0
Thank you!

this formula does indeed work fine for the values provided. However, I tried adapting it to very small values and for some reason it does not round correctly anymore.

=TEXT(B12;INDEX({"0%";"0,0%";"0,00%";"0,000%";"0,0000%";"0,00000%";"0,000000%";"0,0000000%";"0,00000000%";"0,000000000%"};MATCH(TRUE;MOD(B12*1000000000;{10000000;1000000;100000;10000;1000;100;10;1})=0;0)))

With this formula 0,000000005 becomes 0,0000005%, which is correct as far as decimal to % goes, but it should be 0,00000001% if rounded correctly.

Could you provide a small sample of conversion you need to obtain? An image would be enough, an XL2BB table would be better
Sure can (unfortunately, XL2BB is not possible, as I am not allowed to install anything on my company PC):

1728397241762.png


I hope this clears up any confusion I may have produced.

This is only a small sample, and values can be very small, so the formula should allow for at least 10 decimals being 0 before the first non-zero one.
 

Attachments

  • 1728396974010.png
    1728396974010.png
    3.7 KB · Views: 4
Upvote 0
Maybe, in D4 and then copied down:
Excel Formula:
=IFERROR(LET(iVal,A4,iLog,ROUNDUP(LOG10(iVal),0),maybe,IF(ROUND(iVal*100,-iLog-3)=0,ROUND(iVal*100,-iLog-2),ROUND(iVal*100,-iLog-3)),maybe&"%"),NA())

This runs on Office 365
Results are in the image (column C is not necessary for the calculation)
 

Attachments

  • Screenshot 2024-10-08 181944.png
    Screenshot 2024-10-08 181944.png
    17.1 KB · Views: 1
Upvote 0
Maybe, in D4 and then copied down:
Excel Formula:
=IFERROR(LET(iVal,A4,iLog,ROUNDUP(LOG10(iVal),0),maybe,IF(ROUND(iVal*100,-iLog-3)=0,ROUND(iVal*100,-iLog-2),ROUND(iVal*100,-iLog-3)),maybe&"%"),NA())

This runs on Office 365
Results are in the image (column C is not necessary for the calculation)
This works perfectly well for any % smaller than 1; but for % values higher than that the formula rounds more than would be appropriate (such numbers should be displayed as they are with one decimal):

1728458838528.png

In the examples, 31,2000% should be displayed as 31,2%, 4,56% as 4,6% and so on.

Is there a way to iron this out?

Thank you!
 
Upvote 0
What about:
Excel Formula:
=IFERROR(LEFT(A1*100,FIND(MID(SUBSTITUTE(A1,0,""),2,99),A1*100)), LEFT(ROUND(A1*100,1),99))&"%"
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,168
Members
452,615
Latest member
bogeys2birdies

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