79544235

Date: 2025-03-30 06:10:22
Score: 1
Natty:
Report link

I implemented @Mark's answer as a LibreOffice Calc macro, made the number of decimals an option, and added the rest of the prefixes:

' Display a number in engineering notation, using SI prefixes.
' Based on https://stackoverflow.com/a/55382156
Option VBASupport 1
Function ENG(value as Double, decimals)
    normalized = ROUND(value / (1000 ^ INT(LOG(ABS(value))/log(1000))),decimals)
    prefix = CHOOSE(INT(LOG(ABS(value))/log(1000)) + 11, _
                    "q","r","y","z","a","f","p","n","ยต","m","", _
                    "k","M","G","T","P","E","Z","Y","R","Q")
    ENG = normalized & prefix
End Function

I expect it would work in Excel after removing the Option VBASupport 1 line, but haven't tested that yet.

Once it's added and macros are enabled it can be used like any other function in a cell formula (eg =ENG(A1,2)).

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Mark's
Posted by: remcycles