Change high% display to mult form

Also includes some documentation updates from a previous PR (sleeve.setToIdle)
This commit is contained in:
omuretsu 2023-02-19 15:24:27 -05:00
parent 2bd5741b22
commit 6b8ae1b351
7 changed files with 40 additions and 10 deletions

@ -9,7 +9,7 @@ Format a number as a percentage.
**Signature:** **Signature:**
```typescript ```typescript
formatPercent(n: number, fractionalDigits?: number): string; formatPercent(n: number, fractionalDigits?: number, multStart?: number): string;
``` ```
## Parameters ## Parameters
@ -18,6 +18,7 @@ formatPercent(n: number, fractionalDigits?: number): string;
| --- | --- | --- | | --- | --- | --- |
| n | number | Number to format as a percentage. | | n | number | Number to format as a percentage. |
| fractionalDigits | number | _(Optional)_ Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2. | | fractionalDigits | number | _(Optional)_ Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2. |
| multStart | number | _(Optional)_ |
**Returns:** **Returns:**

@ -77,7 +77,7 @@ export async function main(ns) {
| [fileExists(filename, host)](./bitburner.ns.fileexists.md) | Check if a file exists. | | [fileExists(filename, host)](./bitburner.ns.fileexists.md) | Check if a file exists. |
| [flags(schema)](./bitburner.ns.flags.md) | Parse command line flags. | | [flags(schema)](./bitburner.ns.flags.md) | Parse command line flags. |
| [formatNumber(n, fractionalDigits, suffixStart, isInteger)](./bitburner.ns.formatnumber.md) | Format a number. | | [formatNumber(n, fractionalDigits, suffixStart, isInteger)](./bitburner.ns.formatnumber.md) | Format a number. |
| [formatPercent(n, fractionalDigits)](./bitburner.ns.formatpercent.md) | Format a number as a percentage. | | [formatPercent(n, fractionalDigits, multStart)](./bitburner.ns.formatpercent.md) | Format a number as a percentage. |
| [formatRam(n, fractionalDigits)](./bitburner.ns.formatram.md) | Format a number as an amount of ram. | | [formatRam(n, fractionalDigits)](./bitburner.ns.formatram.md) | Format a number as an amount of ram. |
| [ftpcrack(host)](./bitburner.ns.ftpcrack.md) | Runs FTPCrack.exe on a server. | | [ftpcrack(host)](./bitburner.ns.ftpcrack.md) | Runs FTPCrack.exe on a server. |
| [getBitNodeMultipliers(n, lvl)](./bitburner.ns.getbitnodemultipliers.md) | Get the current Bitnode multipliers. | | [getBitNodeMultipliers(n, lvl)](./bitburner.ns.getbitnodemultipliers.md) | Get the current Bitnode multipliers. |

@ -33,6 +33,7 @@ If you are not in BitNode-10, then you must have Source-File 10 in order to use
| [setToCompanyWork(sleeveNumber, companyName)](./bitburner.sleeve.settocompanywork.md) | Set a sleeve to work for a company. | | [setToCompanyWork(sleeveNumber, companyName)](./bitburner.sleeve.settocompanywork.md) | Set a sleeve to work for a company. |
| [setToFactionWork(sleeveNumber, factionName, factionWorkType)](./bitburner.sleeve.settofactionwork.md) | Set a sleeve to work for a faction. | | [setToFactionWork(sleeveNumber, factionName, factionWorkType)](./bitburner.sleeve.settofactionwork.md) | Set a sleeve to work for a faction. |
| [setToGymWorkout(sleeveNumber, gymName, stat)](./bitburner.sleeve.settogymworkout.md) | Set a sleeve to workout at the gym. | | [setToGymWorkout(sleeveNumber, gymName, stat)](./bitburner.sleeve.settogymworkout.md) | Set a sleeve to workout at the gym. |
| [setToIdle(sleeveNumber)](./bitburner.sleeve.settoidle.md) | Set a sleeve to idle. |
| [setToShockRecovery(sleeveNumber)](./bitburner.sleeve.settoshockrecovery.md) | Set a sleeve to shock recovery. | | [setToShockRecovery(sleeveNumber)](./bitburner.sleeve.settoshockrecovery.md) | Set a sleeve to shock recovery. |
| [setToSynchronize(sleeveNumber)](./bitburner.sleeve.settosynchronize.md) | Set a sleeve to synchronize. | | [setToSynchronize(sleeveNumber)](./bitburner.sleeve.settosynchronize.md) | Set a sleeve to synchronize. |
| [setToUniversityCourse(sleeveNumber, university, className)](./bitburner.sleeve.settouniversitycourse.md) | Set a sleeve to take a class at a university. | | [setToUniversityCourse(sleeveNumber, university, className)](./bitburner.sleeve.settouniversitycourse.md) | Set a sleeve to take a class at a university. |

@ -0,0 +1,28 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [Sleeve](./bitburner.sleeve.md) &gt; [setToIdle](./bitburner.sleeve.settoidle.md)
## Sleeve.setToIdle() method
Set a sleeve to idle.
**Signature:**
```typescript
setToIdle(sleeveNumber: number): void;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| sleeveNumber | number | Index of the sleeve to idle. |
**Returns:**
void
## Remarks
RAM cost: 4 GB

@ -1691,11 +1691,11 @@ export const ns: InternalAPI<NSFull> = {
}, },
formatPercent: formatPercent:
(ctx) => (ctx) =>
(_n, _fractionalDigits = 2, _suffixStart = 1e7) => { (_n, _fractionalDigits = 2, _multStart = 1e6) => {
const n = helpers.number(ctx, "n", _n); const n = helpers.number(ctx, "n", _n);
const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits); const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits);
const suffixStart = helpers.number(ctx, "suffixStart", _suffixStart); const multStart = helpers.number(ctx, "multStart", _multStart);
return formatPercent(n, fractionalDigits, suffixStart); return formatPercent(n, fractionalDigits, multStart);
}, },
// Todo: Remove function in 2.3. Until then it just directly wraps numeral. // Todo: Remove function in 2.3. Until then it just directly wraps numeral.
nFormat: (ctx) => (_n, _format) => { nFormat: (ctx) => (_n, _format) => {

@ -6471,10 +6471,10 @@ export interface NS {
* *
* @param n - Number to format as a percentage. * @param n - Number to format as a percentage.
* @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2. * @param fractionalDigits - Number of digits to show in the fractional part of the decimal number. Optional, defaults to 2.
* @param suffixStart - When to attach a suffix to the percentage. Default is 1e7 which is 1b %. * @param suffixStart - When to switch the percentage to a multiplier. Default is 1e6 or x1.00m.
* @returns Formatted percentage. * @returns Formatted percentage.
*/ */
formatPercent(n: number, fractionalDigits?: number, suffixStart?: number): string; formatPercent(n: number, fractionalDigits?: number, multStart?: number): string;
/** /**
* Format a number using the numeral library. This function is deprecated and will be removed in 2.3. * Format a number using the numeral library. This function is deprecated and will be removed in 2.3.

@ -89,7 +89,7 @@ function formatExponential(n: number) {
} }
// Default suffixing starts at 1e9 % which is 1e7. // Default suffixing starts at 1e9 % which is 1e7.
export function formatPercent(n: number, fractionalDigits = 2, suffixStart = 1e7) { export function formatPercent(n: number, fractionalDigits = 2, multStart = 1e6) {
// NaN does not get formatted // NaN does not get formatted
if (Number.isNaN(n)) return "NaN%"; if (Number.isNaN(n)) return "NaN%";
const nAbs = Math.abs(n); const nAbs = Math.abs(n);
@ -97,8 +97,8 @@ export function formatPercent(n: number, fractionalDigits = 2, suffixStart = 1e7
// Special handling for Infinities // Special handling for Infinities
if (nAbs * 100 === Infinity) return n < 0 ? "-∞%" : "∞%"; if (nAbs * 100 === Infinity) return n < 0 ? "-∞%" : "∞%";
// Suffix form adds a space to be less visually confusing. Values this high should rarely be seen. // Mult form. There are probably some areas in the game this wouldn't make sense, but they hopefully won't ever have huge %.
if (nAbs >= suffixStart) return formatNumber(n * 100, fractionalDigits, 0) + " %"; if (nAbs >= multStart) return "x" + formatNumber(n, fractionalDigits, 0);
return getFormatter(fractionalDigits, percentFormats, { style: "percent" }).format(n); return getFormatter(fractionalDigits, percentFormats, { style: "percent" }).format(n);
} }