Keep significant trailing zeros

Asbestos_Jen

Active Member
Joined
May 12, 2017
Messages
279
Office Version
  1. 2007
Platform
  1. Windows
I have data as simplified below. The final result needs to be 2 significant digits, but can't be in scientific notation because the majority of our clients are not scientists. The formula in column E works well when the last significant digit is not zero, but always truncates trailing zeros.

Is there way to keep the trailing zero using formulas? The raw values are calculated from many parameters, I just used values here.

Book2
BCDE
1RawFINAL
2 Raw LimitRaw ResultLimitRESULT
30.0010.000050.001<0.001
40.035563.5211497630.0363.5
50.001000030.0012070.0010.0012
60.0010.0003720.001<0.001
70.03580.464280.0360.46
80.3465303140.0430.35<0.35
90.0012010.0053600640.00120.0054
100.00110.0059907880.00110.006
110.0010030.0065355440.0010.0065
120.000960.0070088730.000960.007
130.000910.0074222510.000910.0074
14
15Correct # digits
Sheet1
Cell Formulas
RangeFormula
D3:D13D3=ROUND($B3,2-(1+INT(LOG10($B3))))
E3:E13E3=IF($C3>$B3,ROUND($C3,2-(1+INT(LOG10($C3)))),"<"&D3)
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
DISREGARD THIS SOLUTION: It works fine when only one digit is showing but it undesirably adds a zero even if there are already two significant digits showing. Back to the drawing board.

You can't do it with formulas, this is a display format issue. I was able to this with conditional formatting, but you have to have a rule for every expected level of precision. And the order matters.

$scratch.xlsm
A
20.60
30.060
40.0060
50.00060
Sig Dig
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A:AExpression=INT(A1*10)=A1*10textNO
A:AExpression=INT(A1*100)=A1*100textNO
A:AExpression=INT(A1*1000)=A1*1000textNO
A:AExpression=INT(A1*10000)=A1*10000textNO


1732751628230.png
 
Upvote 0
DISREGARD THIS SOLUTION: It works fine when only one digit is showing but it undesirably adds a zero even if there are already two significant digits showing. Back to the drawing board.

You can't do it with formulas, this is a display format issue. I was able to this with conditional formatting, but you have to have a rule for every expected level of precision. And the order matters.

$scratch.xlsm
A
20.60
30.060
40.0060
50.00060
Sig Dig
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A:AExpression=INT(A1*10)=A1*10textNO
A:AExpression=INT(A1*100)=A1*100textNO
A:AExpression=INT(A1*1000)=A1*1000textNO
A:AExpression=INT(A1*10000)=A1*10000textNO


View attachment 119769
Thanks for the input.

I would love MS to add a function for this, but it wouldn't help me anyway, since my company still runs Office 2007 or 2010 on all machines.

I remember seeing a VBA solution somewhere once upon a time; I'll see if I can find it again.
 
Upvote 0
OK I think I got it.

$scratch.xlsm
BCDE
1RawFINAL
2Raw LimitRaw ResultLimitRESULT
30.0010.000050.001<0.001
40.035563.521150.0363.5
50.0010.0012070.0010.0012
60.0010.0003720.001<0.001
70.03580.464280.0360.46
80.346530.0430.35<0.35
90.0012010.005360.00120.0054
100.00110.0059910.00110.0060
110.0010030.0065360.0010.0065
120.000960.0070090.000960.0070
130.000910.0074220.000910.0074
14
15Correct # digits
Sheet3
Cell Formulas
RangeFormula
D3:D13D3=ROUND($B3,2-(1+INT(LOG10($B3))))
E3:E13E3=IF($C3>$B3,ROUND($C3,2-(1+INT(LOG10($C3)))),"<"&D3)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E:EExpression=AND(E1*10<10,INT(E1*10)=E1*10)textNO
E:EExpression=AND(E1*100<10,INT(E1*100)=E1*100)textNO
E:EExpression=AND(E1*1000<10,INT(E1*1000)=E1*1000)textNO
E:EExpression=AND(E1*10000<10,INT(E1*10000)=E1*10000)textNO
 
Upvote 0
Solution
What are the actual formats you're using in the conditions? XL2BB doesn't capture conditional formatting for me because my Excel is too old (XL2BBv2.0 because XL2BBv2.1 crashes excel on this computer.)
2024-11-27_Trailing0sd.xlsx
BCDE
1RawFINAL
2Raw LimitRaw ResultLimitRESULT
30.001000.000050.001<0.001
40.035563.521150.0363.5
50.001000.001210.0010.0012
60.001000.000370.001<0.001
70.035800.464280.0360.46
80.346530.043000.35<0.35
90.001200.005360.00120.0054
100.001100.005990.00110.006
110.001000.006540.0010.0065
120.000960.007010.000960.007
130.000910.007420.000910.0074
Sheet2
Cell Formulas
RangeFormula
D3:D13D3=ROUND($B3,2-(1+INT(LOG10($B3))))
E3:E13E3=IF($C3>$B3,ROUND($C3,2-(1+INT(LOG10($C3)))),"<"&$D3)
 

Attachments

  • 1732812936388.png
    1732812936388.png
    37 KB · Views: 1
  • 1732813061814.png
    1732813061814.png
    20.8 KB · Views: 1
  • 1732813096487.png
    1732813096487.png
    14.8 KB · Views: 1
Upvote 0
Here are the custom formats for each rule

=AND(E1*10<10,INT(E1*10)=E1*10)0.00
=AND(E1*100<100,INT(E1*100)=E1*100)0.000
=AND(E1*1000<1000,INT(E1*1000)=E1*1000)0.0000
=AND(E1*10000<10000,INT(E1*10000)=E1*10000)0.00000
 
Upvote 0
That seems to do the job as long as the final result is a number. I'll have to see if I can modify it for the "less than" (text) results.
 
Upvote 0
You can't modify text using that method. You may have to bake it into the formula that produces the text.
 
Upvote 0
I found this UDF at Rounding to Significant Figures in Excel searching for a VBA solution. I think I'll go this way instead of conditional formatting or really ugly nested IFs, which was what I was going to try adapting the cf rules to do.

2024-11-27_Trailing0sd.xlsm
KLMN
1RawFINAL
2 Raw LimitRaw ResultLimitRESULT
30.0010.000050.0010<0.0010
40.035563.5211497630.0363.5
50.001000030.0012070.00100.0012
60.0010.0003720.0010<0.0010
70.03580.464280.0360.46
80.3465303140.0430.35<0.35
90.0012010.0053600640.00120.0054
100.00110000.0059907880.00110.0060
110.0010030.0065355440.00100.0065
120.00096000.0070088730.000960.0070
130.00090000.0074222510.000900.0074
140.00009000.0042225110.0000900.0042
Vertex
Cell Formulas
RangeFormula
M3:M14M3=roundsf(K3,2)
N3:N14N3=IF(L3>K3,roundsf(L3,2),"<"&roundsf(K3,2))


VBA Code:
Function ROUNDSF(num As Variant, sigs As Variant) As String
Dim exponent As Integer
Dim decplace As Integer
Dim fmt_left As String
Dim fmt_right As String
Dim numround As Double
If IsNumeric(num) And IsNumeric(sigs) Then
If sigs < 1 Then
' Return the   "  #NUM  "   error 
            ROUNDSF = CVErr(xlErrNum) 
 Else
            numround = WorksheetFunction.text(num, "." & _ 
 String(sigs, "0") & "E+000") 
If num = 0 Then
                exponent = 0 
 Else
'Round is needed to fix a ?truncation? 
'problem when num = 10, 100, 1000, etc. 
                exponent = Round(Int(Log(Abs(numround)) / Log(10)), 1) 
End If
            decplace = (sigs - (1 + exponent)) 
If decplace > 0 Then
fmt_right = String(decplace, "0") 
                fmt_left = "0." 
 Else
                fmt_right = "" 
                fmt_left = "0" 
End If
            ROUNDSF = WorksheetFunction.text(numround, _ 
                      fmt_left & fmt_right) 
End If
 Else
' Return the   "  #N/A  "   error 
        ROUNDSF = CVErr(xlErrNA) 
End If
End Function
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,245
Members
452,900
Latest member
LisaGo

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