Improve scientific notation formatting

This commit is contained in:
Codex Agent
2026-03-08 10:46:36 +00:00
parent 7996f31f32
commit ca7632bf25
5 changed files with 81 additions and 23 deletions
@@ -1,6 +1,7 @@
<script lang="ts">
import { solve } from '$lib/engine';
import type { CalculatorDef } from '$lib/data/calculators';
import ScientificNotationValue from '$lib/components/ScientificNotationValue.svelte';
export let config: CalculatorDef;
@@ -17,10 +18,6 @@
? solve(config, 1, exampleInput.toString(), '', '')
: null;
$: offset = config.offset ?? 0;
$: formulaExpression = supportsExample
? `${exampleInput} × ${config.factor}${offset ? ` + ${offset}` : ''}`
: '';
const formatExampleValue = (value: number | null): string => {
if (value === null || Number.isNaN(value)) {
return '—';
@@ -50,17 +47,27 @@
<section class="example-card">
<h3>How to convert {config.labels.in1} to {config.labels.in2}</h3>
<p class="example-note">
1 {config.labels.in1} = {config.factor}{config.offset ? ` + ${config.offset}` : ''} {config.labels.in2}
1 {config.labels.in1} =
<ScientificNotationValue value={config.factor} />
{config.offset ? ` + ${config.offset}` : ''} {config.labels.in2}
</p>
<p class="example-note">
1 {config.labels.in2} = {formattedReverseValue} {config.labels.in1}
1 {config.labels.in2} =
<ScientificNotationValue value={formattedReverseValue} fallback="—" />
{config.labels.in1}
</p>
<p class="example-line">
Example: convert {exampleInput} {config.labels.in1} to {config.labels.in2}
</p>
<p class="example-line">
{formulaExpression} =
<span class="example-result">{result.val2} {config.labels.in2}</span>
{exampleInput}
<span class="example-operator">×</span>
<ScientificNotationValue value={config.factor} />
{config.offset ? ` + ${config.offset}` : ''}
=
<span class="example-result">
<ScientificNotationValue value={result.val2} fallback="—" /> {config.labels.in2}
</span>
</p>
</section>
{/if}
@@ -93,6 +100,11 @@
color: var(--text);
}
.example-operator {
margin: 0 0.25rem;
font-weight: 600;
}
.example-result {
font-weight: 600;
margin-left: 0.35rem;