Skip to content

Commit 1de2291

Browse files
committed
format fix
1 parent 4410d8c commit 1de2291

2 files changed

Lines changed: 13 additions & 20 deletions

File tree

src/Synergism.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,20 +2199,20 @@ export const format = (
21992199
mantissa = input.mantissa
22002200
}
22012201

2202+
const threshold = 10 - Math.pow(10, long ? -13 : -7)
22022203
// This prevents numbers from jittering between two different powers by rounding errors
2203-
if (mantissa > 9.9999999) {
2204+
if (mantissa > threshold) {
22042205
mantissa = 1
2205-
;++power
2206+
++power
22062207
}
22072208

22082209
if (mantissa < 1 && mantissa > 0.9999999) {
22092210
mantissa = 1
22102211
}
22112212

22122213
// If the power is less than 100 it's effectively 0
2213-
// To my knowledge the only number that goes as low as e-100 is TD16. Strangely it causes a new bug
2214-
// For pure scientific, where it says "1.00e-,100". I think this is an acceptable side effect
2215-
// Considering that it fixes an issue that quite a few people (including myself) had with this notation || 6030
2214+
// To my knowledge the only number that goes as low as e-100 is TD16. || 6030
2215+
// A bug with 1e-100 being shown as "1.00e-,100" is fixed || rus9384
22162216

22172217
if (power < -100) {
22182218
return '0'
@@ -2232,7 +2232,7 @@ export const format = (
22322232
roundingMode: 'trunc' as const,
22332233
notation: player.notation === 'Pure Engineering' ? 'engineering' as const : 'scientific' as const
22342234
}
2235-
return input.toLocaleString(undefined, formatOpts)
2235+
return input.toLocaleString(undefined, formatOpts).toLowerCase() // We want 'e' to be in lower case
22362236
}
22372237

22382238
// If the power is negative, then we will want to address that separately.
@@ -2281,7 +2281,7 @@ export const format = (
22812281
} else if (power < 6 || (long && power < 12)) {
22822282
// If the power is less than 6 or format long and less than 12 use standard formatting (1,234,567)
22832283
// Gets the standard representation of the number, safe as power is guaranteed to be > -12 and < 12
2284-
let standard = mantissa * Math.pow(10, power)
2284+
let standard = input as number // Avoid rounding errors introduced by multiplying mantissa with 10 ** exponent
22852285
let standardString: string
22862286
let digits = accuracy
22872287
if (power >= 2 + (long ? 1 : 0)) {
@@ -2290,7 +2290,6 @@ export const format = (
22902290
digits = 2
22912291
}
22922292

2293-
Math.max(0, Math.min(accuracy, accuracy + 2 - power))
22942293
// Rounds up if the number experiences a rounding error
22952294
if (standard - Math.floor(standard) > 0.9999999) {
22962295
standard = Math.ceil(standard)
@@ -2321,24 +2320,18 @@ export const format = (
23212320
roundingMode: 'trunc' as const
23222321
}
23232322

2324-
if (power < 1e6) {
2323+
if (power < 1e6 || (longExponent && power < 1e12)) {
23252324
// If the power is less than 1e6 then apply standard scientific/engineering notation
23262325
// Makes mantissa be rounded down to 'accuracy' decimal places
23272326
const mantissaLook = mantissa.toLocaleString(undefined, locOpts)
2328-
//const powerLook = padEvery(power.toString()) // Makes the power group 3 with commas
2329-
const powerLook = power.toLocaleString()
2327+
const powerLook = format(power, 0, longExponent)
23302328
return `${mantissaLook}e${powerLook}` // Returns format (1.23e456,789)
23312329
} else if (power >= 1e6) {
23322330
// The only difference between Default and Pure Scientific is how it handles numbers larger than 1e1M / E1e6 || rus9384
23332331
if (player.notation === 'Pure Scientific') {
23342332
return `E${format(power, 3)}`
23352333
}
23362334

2337-
if (longExponent) {
2338-
const mantissaLook = mantissa.toLocaleString(undefined, locOpts)
2339-
return `${mantissaLook}e${format(power, 0, true)}`
2340-
}
2341-
23422335
// if the power is greater than 1e6 apply notation scientific notation
23432336
// Makes mantissa be rounded down to 2 decimal places
23442337
const mantissaLook = testing && truncate

src/UpdateHTML.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,10 +1115,10 @@ const updateAscensionStats = () => {
11151115
const fillers: Record<string, string> = {
11161116
ascLen: formatTimeShort(player.ascStatToggles[6] ? player.ascensionCounter : player.ascensionCounterReal, 0),
11171117
ascCubes: format(ascensionRewards.wowCubes * (player.ascStatToggles[1] ? 1 : 1 / t), 2),
1118-
ascTess: format(ascensionRewards.wowTesseracts * (player.ascStatToggles[2] ? 1 : 1 / t), 2),
1119-
ascHyper: format(ascensionRewards.wowHypercubes * (player.ascStatToggles[3] ? 1 : 1 / t), 2),
1120-
ascPlatonic: format(ascensionRewards.wowPlatonicCubes * (player.ascStatToggles[4] ? 1 : 1 / t), 2),
1121-
ascHepteract: format(ascensionRewards.wowHepteracts * (player.ascStatToggles[5] ? 1 : 1 / t), 2),
1118+
ascTess: format(ascensionRewards.wowTesseracts * (player.ascStatToggles[2] ? 1 : 1 / t), 3),
1119+
ascHyper: format(ascensionRewards.wowHypercubes * (player.ascStatToggles[3] ? 1 : 1 / t), 4),
1120+
ascPlatonic: format(ascensionRewards.wowPlatonicCubes * (player.ascStatToggles[4] ? 1 : 1 / t), 5),
1121+
ascHepteract: format(ascensionRewards.wowHepteracts * (player.ascStatToggles[5] ? 1 : 1 / t), 3),
11221122
ascC10: format(player.challengecompletions[10]),
11231123
ascTimeAccel: `${format(calculateGlobalSpeedMult(), 3)}x${addedAsteriskHalfMind ? '*' : ''}`,
11241124
ascAscensionTimeAccel: `${format(calculateAscensionSpeedMult(), 3)}x${addedAsteriskOneMind ? '*' : ''}`,

0 commit comments

Comments
 (0)