diff options
| author | Shinigami <[email protected]> | 2022-12-09 09:12:29 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-12-09 09:12:29 +0100 |
| commit | 671631b0efa84ec4ff17827c7263a261de2d3fa0 (patch) | |
| tree | b2c0ed235d657f864e842082822937374657fc5a /src/modules/datatype | |
| parent | 6baa8ceebe63c716a62903f4c8ddaddb799aecdc (diff) | |
| download | faker-671631b0efa84ec4ff17827c7263a261de2d3fa0.tar.xz faker-671631b0efa84ec4ff17827c7263a261de2d3fa0.zip | |
feat(number)!: change float default params (#1642)
Diffstat (limited to 'src/modules/datatype')
| -rw-r--r-- | src/modules/datatype/index.ts | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/modules/datatype/index.ts b/src/modules/datatype/index.ts index b7000dc6..f9c2bac6 100644 --- a/src/modules/datatype/index.ts +++ b/src/modules/datatype/index.ts @@ -83,7 +83,7 @@ export class DatatypeModule { * @deprecated Use `faker.number.float()` instead. */ float( - options?: number | { min?: number; max?: number; precision?: number } + options: number | { min?: number; max?: number; precision?: number } = {} ): number { deprecated({ deprecated: 'faker.datatype.float()', @@ -91,7 +91,16 @@ export class DatatypeModule { since: '8.0', until: '9.0', }); - return this.faker.number.float(options); + + if (typeof options === 'number') { + options = { + precision: options, + }; + } + + const { min = 0, max = min + 99999, precision = 0.01 } = options; + + return this.faker.number.float({ min, max, precision }); } /** @@ -210,7 +219,7 @@ export class DatatypeModule { // This check is required to avoid returning false when float() returns 1 return true; } - return this.faker.number.float({ max: 1 }) < probability; + return this.faker.number.float() < probability; } /** |
