Torque unit record

HTML for this example

Select the code and use your copy shortcut. Changes in this preview are temporary.

<!doctype html><html lang="en-US"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Torque unit record</title><style>*{box-sizing:border-box}html{color-scheme:light}body{margin:0;background:var(--bg,#eef1f4);color:var(--ink,#233449);font:16px/1.5 system-ui,-apple-system,Segoe UI,sans-serif}main{max-width:1040px;margin:auto;padding:26px 28px 44px}header{margin-bottom:20px}h1{font-size:clamp(26px,4vw,36px);letter-spacing:-.035em;line-height:1.15;margin:5px 0 10px}h2{font-size:21px;line-height:1.3;margin:0 0 15px}h3{font-size:17px;margin:0 0 9px}p{margin:8px 0 16px}.kicker{font-size:12px;text-transform:uppercase;letter-spacing:.12em;font-weight:750;color:var(--accent,#315b87)}.muted,small{color:#556473}.panel{margin:20px 0;padding:24px;border:1px solid var(--line,#ccd5df);border-radius:10px;background:#fff}.hero{padding:24px;background:var(--hero,#183b5c);color:#fff;border-radius:12px;margin:18px 0}.hero .kicker,.hero small{color:#d9e5ef}.big{font-size:clamp(32px,5vw,52px);line-height:1.15;font-weight:750;letter-spacing:-.035em;overflow-wrap:anywhere;margin:10px 0 15px}.row{display:flex;flex-wrap:wrap;gap:15px;align-items:end}.row>label{flex:1;min-width:140px}.grid{display:grid;grid-template-columns:1fr 1fr;gap:20px}.thirds{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:15px}label{display:block;font-size:14px;font-weight:650}input,select,textarea{font:inherit;font-size:16px;color:inherit;display:block;width:100%;margin-top:6px;padding:11px 12px;border:1px solid #a9b4c1;border-radius:6px;background:white;min-width:0}input[type=checkbox]{display:inline;width:auto;margin:0 8px 0 0;accent-color:var(--accent,#315b87)}textarea{min-height:100px;resize:vertical}button{font:inherit;font-weight:650;min-height:44px;border:1px solid var(--accent,#315b87);border-radius:6px;background:var(--accent,#315b87);color:white;padding:10px 16px;cursor:pointer}button.secondary{background:white;color:var(--accent,#315b87)}button:disabled{opacity:.5;cursor:default}button[aria-pressed=true]{box-shadow:0 0 0 3px #eab655}button:hover:not(:disabled){filter:brightness(.94)}:focus-visible{outline:3px solid #e5a72f;outline-offset:3px}.actions{display:flex;flex-wrap:wrap;gap:10px;margin:18px 0 0}[hidden]{display:none!important}.error{color:#a3232a;font-weight:650}.error:not(:empty){padding:12px;background:#fff0ed;border-left:4px solid #ab3439;margin:14px 0}.note{padding:14px;background:#edf2f6;border-radius:6px;margin:14px 0}.mono,pre{font-family:ui-monospace,Consolas,monospace;font-variant-numeric:tabular-nums}pre{white-space:pre-wrap;overflow-wrap:anywhere;font-size:14px;line-height:1.7;margin:0}.mono{overflow-wrap:anywhere}table{width:100%;border-collapse:collapse;table-layout:fixed;font-size:14px}th,td{text-align:left;vertical-align:top;overflow-wrap:anywhere;padding:11px 8px;border-bottom:1px solid #d4dce4}th{font-size:12px;text-transform:uppercase;letter-spacing:.035em;color:#536372}th:first-child,td:first-child{padding-left:0}.tag{display:inline-block;padding:4px 8px;border:1px solid currentColor;border-radius:4px;font-size:12px;font-weight:750}.rule{border-top:1px solid #cbd4dd;padding-top:18px}.line{height:30px;border-bottom:1px solid #aab5bf}.stat{font-size:34px;line-height:1.15;font-weight:750}.stat small{font:14px system-ui;display:block;margin-top:8px}details{margin:20px 0;border-top:1px solid #cbd4dd;padding:18px 0}summary{font-weight:700;cursor:pointer}details p{margin-top:15px}a{color:var(--accent,#315b87)}footer{font-size:13px;color:#556473;margin-top:25px}fieldset{min-width:0;border:1px solid #c8d2db;border-radius:7px;padding:18px;margin:15px 0}legend{font-weight:750;padding:0 6px}@media(max-width:720px){main{padding:20px}.panel,.hero{padding:20px}.thirds{gap:10px}}@media(max-width:540px){main{padding:16px}.grid,.thirds{grid-template-columns:1fr}.panel,.hero{padding:18px}.row{gap:12px}.row>label{min-width:100px}h1{font-size:27px}th,td{padding:10px 5px;font-size:13px}.big{font-size:37px}}.torque-comparison{display:grid;grid-template-columns:1fr 1fr;border-top:5px solid #7d5e44;background:#fff;padding:24px;gap:24px}.torque-comparison .big{font-size:32px}.torque-comparison>div+div{border-left:1px solid #cfbeb0;padding-left:24px}@media(max-width:540px){.torque-comparison{grid-template-columns:1fr;padding:18px}.torque-comparison>div+div{padding:18px 0 0;border-left:0;border-top:1px solid #cfbeb0}}</style></head><body style="--bg:#f3f0ea;--accent:#76583c;--hero:#504334"><main><header><div class="kicker">Working example</div><h1>Torque unit record</h1><p class="muted">Confirm torque and pound-force before choosing foot or inch units.</p></header>
<section class="torque-comparison"><div><span class="kicker">Supplied example · 10 lbf·ft</span><div class="big">13.55818 N·m</div></div><div><span class="kicker">Same number · 10 lbf·in</span><div class="big">1.129848 N·m</div></div></section>
<section id="result" class="hero" hidden aria-live="polite"><div class="kicker">Supplied torque magnitude</div><div class="big" id="converted"></div><p id="basis"></p></section><p id="error" class="error" role="alert"></p><form id="form" class="panel" novalidate><label for="raw">Original unit label · preserved as written<input id="raw" value="lb-ft" inputmode="text" autocomplete="off"></label><p><label><input type="checkbox" id="confirmed">I confirm the source describes torque; any pound unit means pound-force.</label></p><div id="typedLabel"><label for="value">Magnitude · manually typed<input id="value" value="" inputmode="decimal" autocomplete="off"></label></div><div id="computedBlock" class="note" hidden><strong>Calculated input · unrounded</strong><p id="computedText" class="mono"></p><button type="button" class="secondary" id="edit">Enter a typed value instead</button></div><div class="row" style="margin-top:18px"><label for="from">Confirmed source unit<select id="from"><option value="">Choose a unit explicitly</option><option value="nm">N·m · newton meter</option><option value="ft">lbf·ft · pound-force foot</option><option value="in">lbf·in · pound-force inch</option></select></label><label for="to">Destination unit<select id="to"><option value="nm">N·m · newton meter</option><option value="ft">lbf·ft · pound-force foot</option><option value="in">lbf·in · pound-force inch</option></select></label></div><div class="actions"><button>Convert</button><button type="button" id="swap" class="secondary" disabled>Swap using unrounded result</button><button type="button" id="reset" class="secondary">Reset</button></div><p id="swapReason" class="muted">Calculate a valid record before swapping.</p></form><section class="panel"><h2>Inspect the printed-factor difference</h2><table><thead><tr><th>Source</th><th>NIST printed factor</th><th>N·m</th></tr></thead><tbody><tr><td>10 lbf·ft</td><td>1.355818</td><td>13.558180</td></tr><tr><td>120 lbf·in</td><td>0.1129848</td><td>13.558176</td></tr></tbody></table><p>Difference: 0.000004 N·m from independently rounded printed factors.</p><div class="actions"><button type="button" id="sample" class="secondary">Use confirmed 10 lbf·ft example</button></div></section><section class="panel"><h2>Calculation record</h2><pre id="trace"></pre></section><details><summary>Precision and supported scope</summary><p>Manually type nonnegative dot decimals with a leading digit, at most six decimal places, and a maximum of 1,000,000. Zero is valid; blanks, commas, exponents, unsupported units and negative magnitudes are rejected. Inputs and units clear prior results until Convert. Calculated Swap input retains its exact rational value separately from typed text.</p><p>Displays use up to six places, half-up. Positive values below 0.000001 use a less-than label. The printed torque factors are not silently supplemented with more digits. No mass, energy, equipment setting, lever force, calibration, or safe limit is determined.</p><p><a href="https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors/nist-guide-si-appendix-b9">NIST printed torque factors</a></p></details><footer>Local example · No information is sent or saved.</footer></main><script>const $=id=>document.getElementById(id);const esc=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));function gcd(a,b){return b?gcd(b,a%b):a}function rat(n,d=1n){const g=gcd(n,d);return {n:n/g,d:d/g}}function mul(a,b){return rat(a.n*b.n,a.d*b.d)}function div(a,b){return rat(a.n*b.d,a.d*b.n)}function rounded(r,p=6){const scale=10n**BigInt(p),q=(r.n*scale*2n+r.d)/(2n*r.d),s=q.toString().padStart(p+1,'0');return p?s.slice(0,-p)+'.'+s.slice(-p):s}function show(r,unit=''){if(r.n>0n&&r.n*1000000n<r.d)return '<0.000001 '+unit;return '≈ '+rounded(r,6).replace(/([.][0-9]*?)0+$/,'$1').replace(/[.]$/,'')+' '+unit}function decimal(s,name,max=1000000,places=6){if(!new RegExp('^[0-9]+(?:[.][0-9]{1,'+places+'})?$').test(s)||s.length>35)throw Error(name+': enter a nonnegative dot-decimal number, up to '+places+' decimal places.');let [a,b='']=s.split('.');const r=rat(BigInt(a+b),10n**BigInt(b.length));if(r.n>BigInt(max)*r.d)throw Error(name+': maximum is '+max+'.');return r}function whole(s,name,max){if(!/^[0-9]+$/.test(s)||s.length>15||Number(s)>max)throw Error(name+': enter an integer from 0 to '+max+'.');return Number(s)}function onForm(fn,clear){$('form').addEventListener('submit',e=>{e.preventDefault();fn()});$('form').addEventListener('input',clear);$('form').addEventListener('change',clear)}

const torque=true;const labels={"nm":"N·m · newton meter","ft":"lbf·ft · pound-force foot","in":"lbf·in · pound-force inch"};const factors=torque?{nm:rat(1n),ft:rat(1355818n,1000000n),in:rat(1129848n,10000000n)}:{us:rat(3785412n,1000000n),imp:rat(454609n,100000n),lpm:rat(1n),lps:rat(60n),m3h:rat(1000n,60n)};function conversion(x,from,to,confirmed=true){if(!factors[from]||!factors[to])throw Error('Choose supported, explicit source and destination units.');if(torque&&!confirmed)throw Error('Confirm torque magnitude and pound-force meaning before converting.');const input=typeof x==='string'?decimal(x,'Value'):x;if(input.n<0n||input.n>1000000n*input.d)throw Error('Calculated input exceeds the 1,000,000 range.');const canonical=mul(input,factors[from]),output=div(canonical,factors[to]);return {input,from,to,canonical,output,swapAllowed:output.n<=1000000n*output.d}}let calculated=null,last=null;
function invalidate(){last=null;$('result').hidden=true;$('trace').textContent='';$('error').textContent='';$('swap').disabled=true;$('swapReason').textContent='Inputs changed. Convert to build a current record.';}function manual(){calculated=null;$('computedBlock').hidden=true;$('typedLabel').hidden=false;invalidate()}function run(){try{const r=conversion(calculated||$('value').value,$('from').value,$('to').value,!torque||$('confirmed').checked);last=r;$('result').hidden=false;$('error').textContent='';$('converted').textContent=show(r.output,labels[r.to]);$('basis').textContent=(calculated?'Calculated input':'Typed input')+' → '+labels[r.from]+' → '+labels[r.to];$('swap').disabled=!r.swapAllowed;$('swapReason').textContent=r.swapAllowed?'Swap uses the stored result, never its rounded display.':'Swap disabled: the calculated value exceeds the 1,000,000 input limit.';$('trace').textContent=(torque?'Quantity: supplied torque magnitude\nRaw source label: '+$('raw').value+'\n':'Quantity: volumetric flow\n')+'Input '+r.input.n+' / '+r.input.d+' '+labels[r.from]+'\nCanonical '+(torque?'N·m':'L/min')+': '+r.canonical.n+' / '+r.canonical.d+'\nFormula: value × ('+factors[r.from].n+'/'+factors[r.from].d+') ÷ ('+factors[r.to].n+'/'+factors[r.to].d+')\nOutput (exact within printed-factor model): '+r.output.n+' / '+r.output.d+' '+labels[r.to]+'\nDisplay: '+$('converted').textContent+'\nPrinted factor precision and display rounding are separate limitations.';}catch(e){invalidate();$('error').textContent=e.message}}
$('form').addEventListener('submit',e=>{e.preventDefault();run()});$('value').addEventListener('input',()=>{calculated=null;invalidate()});['from','to'].forEach(x=>$(x).addEventListener('change',()=>{if(calculated){$('value').value='';manual()}else invalidate()}));if(torque){$('confirmed').addEventListener('change',invalidate);$('raw').addEventListener('input',()=>{$('confirmed').checked=false;invalidate()})}$('edit').onclick=()=>{$('value').value='';manual();$('value').focus()};$('swap').onclick=()=>{if(!last||!last.swapAllowed)return;const r=last;calculated=r.output;$('from').value=r.to;$('to').value=r.from;$('typedLabel').hidden=true;$('computedBlock').hidden=false;$('computedText').textContent=calculated.n+' / '+calculated.d+' '+labels[r.to];run()};$('reset').onclick=()=>{$('value').value='';$('from').value='';$('to').value='nm';if(torque){$('raw').value='';$('confirmed').checked=false}manual();$('swapReason').textContent='Calculate a valid record before swapping.'};$('sample').onclick=()=>{calculated=null;$('typedLabel').hidden=false;$('computedBlock').hidden=true;$('value').value=torque?'10':'2';$('from').value=torque?'ft':'us';$('to').value='nm';if(torque){$('raw').value='lb-ft';$('confirmed').checked=true}run()};$('to').value='nm';</script>
<script>
// Local calculation controls: no native form submission or sandbox permissions required.
(()=>{const form=document.getElementById('form');if(!form)throw Error('Calculation form missing');const dispatch=()=>form.dispatchEvent(new Event('submit',{bubbles:true,cancelable:true}));const buttons=[...form.querySelectorAll('button')].filter(button=>button.type==='submit');if(buttons.length!==1)throw Error('Expected one calculation control');for(const button of buttons){button.type='button';button.addEventListener('click',dispatch);}form.addEventListener('keydown',event=>{if(event.key==='Enter'&&!event.isComposing&&['INPUT','SELECT'].includes(event.target.tagName)){event.preventDefault();dispatch();}});})();
</script>
</body></html>