Template:Chem molar mass/format/sandbox

{{#if:{{{fixed|}}}|{{#ifexpr:{{{value|}}}>0|Category:Chem-molar-mass both hardcoded and calculated}}}}{{#iferror:{{{value|}}}|{{#if:{{{fixed|}}}|{{{fixed|}}}|[cannot calculate]}}{{main other|Category:Articles with erroneous molar mass calculations}}|{{#ifeq:{{{sortable|no}}}|yes|{{ntsh|1={{#if:{{{fixed|}}}|{{#invoke:String|match|s={{{fixed|}}} |pattern=^[%d%.%-%−]+ |plain=false |nomatch={{{fixed|0}}}}} |{{{value|0}}} }} |debug=no}} }}{{#if:{{{fixed|}}}|{{{fixed|}}}|

{{#ifexpr:{{{value|0}}}=0||{{val|{{#invoke:math|precision_format |{{{value|0}}}

|{{#switch:{{{round|smart}}}

|yes={{min|2|{{{smart_round|2}}}}}

|no={{{smart_round|2}}}

||default|smart={{{smart_round|2}}}

|#default={{min|{{{round|0}}}|{{{smart_round|2}}}}}}}

}} }} }} }}}}{{#ifexpr:{{{value|0}}}=0||{{#ifeq:|{{{sortable|unk}}}|no| {{#if:{{{unit|}}} |{{{unit|}}}|g·mol−1}}}}}}{{{ref|}}}{{#if:{{{comment|}}}| {{{comment|}}}}}{{documentation|1=Template:Chem molar mass/doc}}