2022-10-21 17:16:00 +02:00
|
|
|
|
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
|
|
|
|
|
|
|
|
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [printf](./bitburner.ns.printf.md)
|
|
|
|
|
|
|
|
|
|
## NS.printf() method
|
|
|
|
|
|
|
|
|
|
Prints a formatted string to the script’s logs.
|
|
|
|
|
|
2023-02-11 19:18:50 +01:00
|
|
|
|
**Signature:**
|
2022-10-21 17:16:00 +02:00
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
printf(format: string, ...args: any[]): void;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
|
|
|
|
|
|
| Parameter | Type | Description |
|
|
|
|
|
| --- | --- | --- |
|
|
|
|
|
| format | string | Format of the message. |
|
|
|
|
|
| args | any\[\] | Value(s) to be printed. |
|
|
|
|
|
|
2023-02-11 19:18:50 +01:00
|
|
|
|
**Returns:**
|
2022-10-21 17:16:00 +02:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
|
|
|
|
## Remarks
|
|
|
|
|
|
|
|
|
|
RAM cost: 0 GB
|
|
|
|
|
|
|
|
|
|
- See [print](./bitburner.ns.print.md) for how to add color to your printed strings.
|
|
|
|
|
|
|
|
|
|
- For more detail, see: https://github.com/alexei/sprintf.js
|
|
|
|
|
|
2023-04-28 20:19:30 +02:00
|
|
|
|
## Example
|
2022-10-21 17:16:00 +02:00
|
|
|
|
|
|
|
|
|
|
2023-04-28 20:19:30 +02:00
|
|
|
|
```js
|
2022-10-21 17:16:00 +02:00
|
|
|
|
const name = "Bit";
|
|
|
|
|
const age = 4;
|
|
|
|
|
ns.printf("My name is %s.", name);
|
|
|
|
|
ns.printf("I'm %d seconds old.", age);
|
|
|
|
|
ns.printf("My age in binary is %b.", age);
|
|
|
|
|
ns.printf("My age in scientific notation is %e.", age);
|
|
|
|
|
ns.printf("In %d seconds, I'll be %s.", 6, "Byte");
|
2024-05-27 23:42:31 +02:00
|
|
|
|
ns.printf("Am I a nibble? %t", (4 === age));
|
2022-10-21 17:16:00 +02:00
|
|
|
|
ns.tail();
|
|
|
|
|
```
|
|
|
|
|
|