mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
Change high% display to mult form
Also includes some documentation updates from a previous PR (sleeve.setToIdle)
This commit is contained in:
parent
2bd5741b22
commit
6b8ae1b351
@ -9,7 +9,7 @@ Format a number as a percentage.
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
formatPercent(n: number, fractionalDigits?: number): string;
|
||||
formatPercent(n: number, fractionalDigits?: number, multStart?: number): string;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
@ -18,6 +18,7 @@ formatPercent(n: number, fractionalDigits?: number): string;
|
||||
| --- | --- | --- |
|
||||
| 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. |
|
||||
| multStart | number | _(Optional)_ |
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -77,7 +77,7 @@ export async function main(ns) {
|
||||
| [fileExists(filename, host)](./bitburner.ns.fileexists.md) | Check if a file exists. |
|
||||
| [flags(schema)](./bitburner.ns.flags.md) | Parse command line flags. |
|
||||
| [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. |
|
||||
| [ftpcrack(host)](./bitburner.ns.ftpcrack.md) | Runs FTPCrack.exe on a server. |
|
||||
| [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. |
|
||||
| [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. |
|
||||
| [setToIdle(sleeveNumber)](./bitburner.sleeve.settoidle.md) | Set a sleeve to idle. |
|
||||
| [setToShockRecovery(sleeveNumber)](./bitburner.sleeve.settoshockrecovery.md) | Set a sleeve to shock recovery. |
|
||||
| [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. |
|
||||
|
28
markdown/bitburner.sleeve.settoidle.md
Normal file
28
markdown/bitburner.sleeve.settoidle.md
Normal file
@ -0,0 +1,28 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Sleeve](./bitburner.sleeve.md) > [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:
|
||||
(ctx) =>
|
||||
(_n, _fractionalDigits = 2, _suffixStart = 1e7) => {
|
||||
(_n, _fractionalDigits = 2, _multStart = 1e6) => {
|
||||
const n = helpers.number(ctx, "n", _n);
|
||||
const fractionalDigits = helpers.number(ctx, "fractionalDigits", _fractionalDigits);
|
||||
const suffixStart = helpers.number(ctx, "suffixStart", _suffixStart);
|
||||
return formatPercent(n, fractionalDigits, suffixStart);
|
||||
const multStart = helpers.number(ctx, "multStart", _multStart);
|
||||
return formatPercent(n, fractionalDigits, multStart);
|
||||
},
|
||||
// Todo: Remove function in 2.3. Until then it just directly wraps numeral.
|
||||
nFormat: (ctx) => (_n, _format) => {
|
||||
|
4
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
4
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -6471,10 +6471,10 @@ export interface NS {
|
||||
*
|
||||
* @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 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.
|
||||
*/
|
||||
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.
|
||||
|
@ -89,7 +89,7 @@ function formatExponential(n: number) {
|
||||
}
|
||||
|
||||
// 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
|
||||
if (Number.isNaN(n)) return "NaN%";
|
||||
const nAbs = Math.abs(n);
|
||||
@ -97,8 +97,8 @@ export function formatPercent(n: number, fractionalDigits = 2, suffixStart = 1e7
|
||||
// Special handling for Infinities
|
||||
if (nAbs * 100 === Infinity) return n < 0 ? "-∞%" : "∞%";
|
||||
|
||||
// Suffix form adds a space to be less visually confusing. Values this high should rarely be seen.
|
||||
if (nAbs >= suffixStart) return formatNumber(n * 100, fractionalDigits, 0) + " %";
|
||||
// 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 >= multStart) return "x" + formatNumber(n, fractionalDigits, 0);
|
||||
|
||||
return getFormatter(fractionalDigits, percentFormats, { style: "percent" }).format(n);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user