How to get excel to display a certain number of significant figures?

前端 未结 10 1231
太阳男子
太阳男子 2021-01-05 04:10

I am using excel and i want to display a value to a certain number of significant figures.

I tried using the following equation

=ROUND(value,sigfigs-         


        
相关标签:
10条回答
  • 2021-01-05 04:33

    I added to your formula so it also automatically displays the correct number of decimal places. In the formula below, replace the digit "2" with the number of decimal places that you want, which means you would need to make four replacements. Here is the updated formula:

    =TEXT(ROUND(A1,2-1-INT(LOG10(ABS(A1)))),"0"&IF(INT(LOG10(ABS(ROUND(A1,2-1-INT(LOG10(ABS(A1)))))))<1,"."&REPT("0",2-1-INT(LOG10(ABS(ROUND(A1,2-1-INT(LOG10(ABS(A1)))))))),""))
    

    For example, if cell A1 had the value =1/3000, which is 0.000333333.., the above formula as-written outputs 0.00033.

    0 讨论(0)
  • 2021-01-05 04:35

    The formula below works fine. The number of significant figures is set in the first text formula. 0.00 and 4 for 3sf, 0.0 and 3 for 2sf, 0.0000 and 6 for 5sf, etc.

    =(LEFT((TEXT(A1,"0.00E+000")),4))*POWER(10,
    (RIGHT((TEXT(A1,"0.00E+000")),4)))
    

    The formula is valid for E+/-999, if you have a number beyond this increase the number of the last three zeros, and change the second 4 to the number of zeros +1.

    Note that the values displayed are rounded to the significant figures, and should by used for display/output only. If you are doing further calcs, use the original value in A1 to avoid propagating minor errors.

    0 讨论(0)
  • 2021-01-05 04:37

    WARNING: crazy-long excel formula ahead

    I was also looking to work with significant figures and I was unable to use VBA as the spreadsheets can't support them. I went to this question/answer and many other sites but all the answers don't seem to deal with all numbers all the time. I was interested in the accepted answer and it got close but as soon as my numbers were < 0.1 I got a #value! error. I'm sure I could have fixed it but I was already down a path and just pressed on.

    Problem:

    I needed to report a variable number of significant figures in positive and negative mode with numbers from 10^-5 to 10^5. Also, according to the client (and to purple math), if a value of 100 was supplied and was accurate to +/- 1 and we wish to present with 3 sig figs the answer should be '100.' so I included that as well.

    Solution:

    My solution is for an excel formula that returns the text value with required significant figures for positive and negative numbers.

    It's long, but appears to generate the correct results according to my testing (outlined below) regardless of number and significant figures requested. I'm sure it can be simplified but that isn't currently in scope. If anyone wants to suggest a simplification, please leave me a comment!

    =TEXT(IF(A1<0,"-","")&LEFT(TEXT(ABS(A1),"0."&REPT("0",sigfigs-1)&"E+00"),sigfigs+1)*10^FLOOR(LOG10(TEXT(ABS(A1),"0."&REPT("0",sigfigs-1)&"E+00")),1),(""&(IF(OR(AND(FLOOR(LOG10(TEXT(ABS(A1),"0."&REPT("0",sigfigs-1)&"E+00")),1)+1=sigfigs,RIGHT(LEFT(TEXT(ABS(A1),"0."&REPT("0",sigfigs-1)&"E+00"),sigfigs+1)*10^FLOOR(LOG10(TEXT(ABS(A1),"0."&REPT("0",sigfigs-1)&"E+00")),1),1)="0"),LOG10(TEXT(ABS(A1),"0."&REPT("0",sigfigs-1)&"E+00"))<=sigfigs-1),"0.","#")&REPT("0",IF(sigfigs-1-(FLOOR(LOG10(TEXT(ABS(A1),"0."&REPT("0",sigfigs-1)&"E+00")),1))>0,sigfigs-1-(FLOOR(LOG10(TEXT(ABS(A1),"0."&REPT("0",sigfigs-1)&"E+00")),1)),0)))))
    

    Note: I have a named range called "sigfigs" and my numbers start in cell A1

    Test Results:

    I've tested it against the wikipedia list of examples and my own examples so far in positive and negative. I've also tested with a few values that gave me issues early on and all seem to produce the correct results.

    I've also tested with a few values that gave me issues early on and all seem to produce the correct results now.

    3 Sig Figs Test

    99.99 -> 100.
    99.9 -> 99.9
    100 -> 100.
    101 -> 101
    

    Notes:

    Treating Negative Numbers

    To Treat Negative Numbers, I have included a concatenation with a negative sign if less than 0 and use the absolute value for all other work.

    Method of construction: It was initially divided into about 6 columns in excel that performed the various steps and at the end I merged all of the steps into one formula above.

    0 讨论(0)
  • 2021-01-05 04:38

    Rounding to significant digits is one thing... addressed above. Formatting to a specific number of digits is another... and I'll post it here for those of you trying to do what I was and ended up here (as I will likely do again in the future)...

    Example to display four digits:

    .

    Use Home > Styles > Conditional Formatting

    New Rule > Format only cells that contain

    Cell Value > between > -10 > 10 > Format Number 3 decimal places

    New Rule > Format only cells that contain

    Cell Value > between > -100 > 100 > Format Number 2 decimal places

    New Rule > Format only cells that contain

    Cell Value > between > -1000 > 1000 > Format Number 1 decimal place

    New Rule > Format only cells that contain

    Cell Value > not between > -1000 > 1000 > Format Number 0 decimal places

    .

    Be sure these are in this order and check all of the "Stop If True" boxes.

    0 讨论(0)
提交回复
热议问题