formula for B1:
=1*SUBSTITUTE(A1;REGEX(A1;"[RkMG]");VLOOKUP(REGEX(A1;"[RkMG]");$G$1:$H$4;2;0))
Content of G1:H4
R | , |
---|---|
k | 000, |
M | 000000, |
G | 000000000, |
resistor_sort.ods (12.4 KB)
in case your use decimalpoint instead decimalcomma change Column H to your needs
bonus: Direct Sort of CurrentSelection by Resistor_syntax in python:
edit: corrections in python
import re
rex = re.compile(r'([RkMG])')
def repl(resistor):
value, unit, decimals = rex.split(resistor[0])
return ("RkMG".index(unit), float(f"{value}.{decimals}"))
def sort_resistors():
sel = XSCRIPTCONTEXT.getDocument().CurrentSelection
resistors = sel.DataArray
sel.DataArray = sorted(resistors, key=repl)