Revert "Improve scientific notation formatting"

This reverts commit ca7632bf25.
This commit is contained in:
Codex Agent
2026-03-08 18:41:14 +00:00
parent cf0b72269c
commit f315ff1dc1
5 changed files with 23 additions and 81 deletions

View File

@@ -6,7 +6,6 @@
import QuickDefinitionCard from '$lib/components/QuickDefinitionCard.svelte'; import QuickDefinitionCard from '$lib/components/QuickDefinitionCard.svelte';
import QuickConversionExample from '$lib/components/QuickConversionExample.svelte'; import QuickConversionExample from '$lib/components/QuickConversionExample.svelte';
import QuickConversionTable from '$lib/components/QuickConversionTable.svelte'; import QuickConversionTable from '$lib/components/QuickConversionTable.svelte';
import ScientificNotationValue from '$lib/components/ScientificNotationValue.svelte';
export let config: CalculatorDef; export let config: CalculatorDef;
export let showTitle = true; export let showTitle = true;
@@ -148,9 +147,7 @@
</button> </button>
{#if config.factor && config.type === 'standard'} {#if config.factor && config.type === 'standard'}
<span class="formula-hint"> <span class="formula-hint">
1 {config.labels.in1} = 1 {config.labels.in1} = {config.factor}{config.offset ? ` + ${config.offset}` : ''} {config.labels.in2}
<ScientificNotationValue value={config.factor} />
{config.offset ? ` + ${config.offset}` : ''} {config.labels.in2}
</span> </span>
{/if} {/if}
</div> </div>

View File

@@ -1,7 +1,6 @@
<script lang="ts"> <script lang="ts">
import { solve } from '$lib/engine'; import { solve } from '$lib/engine';
import type { CalculatorDef } from '$lib/data/calculators'; import type { CalculatorDef } from '$lib/data/calculators';
import ScientificNotationValue from '$lib/components/ScientificNotationValue.svelte';
export let config: CalculatorDef; export let config: CalculatorDef;
@@ -18,6 +17,10 @@
? solve(config, 1, exampleInput.toString(), '', '') ? solve(config, 1, exampleInput.toString(), '', '')
: null; : null;
$: offset = config.offset ?? 0; $: offset = config.offset ?? 0;
$: formulaExpression = supportsExample
? `${exampleInput} × ${config.factor}${offset ? ` + ${offset}` : ''}`
: '';
const formatExampleValue = (value: number | null): string => { const formatExampleValue = (value: number | null): string => {
if (value === null || Number.isNaN(value)) { if (value === null || Number.isNaN(value)) {
return '—'; return '—';
@@ -47,27 +50,17 @@
<section class="example-card"> <section class="example-card">
<h3>How to convert {config.labels.in1} to {config.labels.in2}</h3> <h3>How to convert {config.labels.in1} to {config.labels.in2}</h3>
<p class="example-note"> <p class="example-note">
1 {config.labels.in1} = 1 {config.labels.in1} = {config.factor}{config.offset ? ` + ${config.offset}` : ''} {config.labels.in2}
<ScientificNotationValue value={config.factor} />
{config.offset ? ` + ${config.offset}` : ''} {config.labels.in2}
</p> </p>
<p class="example-note"> <p class="example-note">
1 {config.labels.in2} = 1 {config.labels.in2} = {formattedReverseValue} {config.labels.in1}
<ScientificNotationValue value={formattedReverseValue} fallback="—" />
{config.labels.in1}
</p> </p>
<p class="example-line"> <p class="example-line">
Example: convert {exampleInput} {config.labels.in1} to {config.labels.in2} Example: convert {exampleInput} {config.labels.in1} to {config.labels.in2}
</p> </p>
<p class="example-line"> <p class="example-line">
{exampleInput} {formulaExpression} =
<span class="example-operator">×</span> <span class="example-result">{result.val2} {config.labels.in2}</span>
<ScientificNotationValue value={config.factor} />
{config.offset ? ` + ${config.offset}` : ''}
=
<span class="example-result">
<ScientificNotationValue value={result.val2} fallback="—" /> {config.labels.in2}
</span>
</p> </p>
</section> </section>
{/if} {/if}
@@ -100,11 +93,6 @@
color: var(--text); color: var(--text);
} }
.example-operator {
margin: 0 0.25rem;
font-weight: 600;
}
.example-result { .example-result {
font-weight: 600; font-weight: 600;
margin-left: 0.35rem; margin-left: 0.35rem;

View File

@@ -1,19 +1,20 @@
<script lang="ts"> <script lang="ts">
import { solve } from '$lib/engine'; import { solve } from '$lib/engine';
import ScientificNotationValue from '$lib/components/ScientificNotationValue.svelte'; import { parseScientificNotation, type ScientificNotationParts } from '$lib/utils/formatScientific';
import type { CalculatorDef } from '$lib/data/calculators'; import type { CalculatorDef } from '$lib/data/calculators';
export let config: CalculatorDef; export let config: CalculatorDef;
const numericSamples = [0.1, 0.5, 1, 2, 5, 10, 20, 50, 100]; const numericSamples = [0.1, 0.5, 1, 2, 5, 10, 20, 50, 100];
type Row = { input: number; output: string }; type Row = { input: number; output: string; scientific?: ScientificNotationParts };
const buildRow = (value: number): Row => { const buildRow = (value: number): Row => {
const formatted = solve(config, 1, value.toString(), '', ''); const formatted = solve(config, 1, value.toString(), '', '');
return { return {
input: value, input: value,
output: formatted.val2 || '—', output: formatted.val2 || '—',
scientific: formatted.val2 ? parseScientificNotation(formatted.val2) ?? undefined : undefined,
}; };
}; };
@@ -44,7 +45,14 @@
<p class="chart-statement"> <p class="chart-statement">
Converting {row.input} <span class="chart-unit">{inputLabel}</span> into <span class="chart-unit">{outputLabel}</span> equals Converting {row.input} <span class="chart-unit">{inputLabel}</span> into <span class="chart-unit">{outputLabel}</span> equals
<span class="chart-output-value"> <span class="chart-output-value">
<ScientificNotationValue value={row.output} fallback="—" /> {#if row.scientific}
<span class="scientific-base">{row.scientific.base}</span>
<span class="scientific-suffix">
×10<sup>{row.scientific.exponent}</sup>
</span>
{:else}
{row.output}
{/if}
</span> </span>
<span class="chart-output-unit">{outputLabel}</span>. <span class="chart-output-unit">{outputLabel}</span>.
</p> </p>

View File

@@ -1,46 +0,0 @@
<script lang="ts">
import { parseScientificNotation, type ScientificNotationParts } from '$lib/utils/formatScientific';
export let value: string | number | null | undefined = null;
export let fallback = '—';
export let className = '';
const formattedValue = value == null ? '' : `${value}`;
const scientific: ScientificNotationParts | null = formattedValue
? parseScientificNotation(formattedValue)
: null;
</script>
{#if scientific}
<span class={`scientific-notation ${className}`.trim()}>
<span class="scientific-base">{scientific.base}</span>
<span class="scientific-suffix">
×10<sup>{scientific.exponent}</sup>
</span>
</span>
{:else}
<span class={`scientific-plain ${className}`.trim()}>
{formattedValue || fallback}
</span>
{/if}
<style>
.scientific-notation,
.scientific-plain {
display: inline-flex;
align-items: baseline;
gap: 0.15rem;
}
.scientific-suffix {
display: inline-flex;
align-items: baseline;
gap: 0.15rem;
font-size: 0.85em;
}
.scientific-suffix sup {
font-size: 0.75em;
vertical-align: super;
}
</style>

View File

@@ -5,7 +5,6 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import type { PageData } from './$types'; import type { PageData } from './$types';
import { buildSeoMeta, canonicalUrl, SITE_NAME, SITE_URL, toJsonLd } from '$lib/seo'; import { buildSeoMeta, canonicalUrl, SITE_NAME, SITE_URL, toJsonLd } from '$lib/seo';
import ScientificNotationValue from '$lib/components/ScientificNotationValue.svelte';
export let data: PageData; export let data: PageData;
@@ -106,18 +105,14 @@
<p> <p>
The conversion between {calc.labels.in1.toLowerCase()} and {calc.labels.in2.toLowerCase()} The conversion between {calc.labels.in1.toLowerCase()} and {calc.labels.in2.toLowerCase()}
uses a fixed multiplication factor. One {calc.labels.in1.toLowerCase().replace(/s$/, '')} equals uses a fixed multiplication factor. One {calc.labels.in1.toLowerCase().replace(/s$/, '')} equals
<ScientificNotationValue value={calc.factor} /> {calc.factor}{calc.offset ? ` plus an offset of ${calc.offset}` : ''} {calc.labels.in2.toLowerCase()}.
{calc.offset ? ` plus an offset of ${calc.offset}` : ''} {calc.labels.in2.toLowerCase()}.
{#if calc.offset} {#if calc.offset}
This offset is common in temperature conversions, where scales differ not just in magnitude but also in their zero point. This offset is common in temperature conversions, where scales differ not just in magnitude but also in their zero point.
{/if} {/if}
</p> </p>
<p> <p>
To convert, multiply the value in {calc.labels.in1.toLowerCase()} by To convert, multiply the value in {calc.labels.in1.toLowerCase()} by {calc.factor}{calc.offset ? `, then add ${calc.offset}` : ''}.
<ScientificNotationValue value={calc.factor} /> To convert in the opposite direction, {calc.offset ? `subtract ${calc.offset}, then ` : ''}divide by {calc.factor}.
{calc.offset ? `, then add ${calc.offset}` : ''}.
To convert in the opposite direction, {calc.offset ? `subtract ${calc.offset}, then ` : ''}divide by
<ScientificNotationValue value={calc.factor} />.
</p> </p>
{:else if calc.type === '3col' || calc.type === '3col-mul'} {:else if calc.type === '3col' || calc.type === '3col-mul'}
<p> <p>