Skip to content

Rethink the commerce.price methodย #2579

@ST-DDT

Description

@ST-DDT

Currently the price method generates prices like this "$5.39". This has several drawbacks, as some currency symbols are written behind the price instead of in front. Some might want an extra space...
There is also the thing about the prices, that require fine tuning of the dec parameter depending on the generated value.
e.g.

// v8.3.1
faker.commerce.price({ min: 0.001, max: 0.009 }) // [Error]: No integer value between 0.001 and 0.009 found.
// #2458
faker.commerce.price({ min: 0.001, max: 0.009 }) // [Error]: No integer value between 0.01 and 0.09 found.
faker.commerce.price({ min: 0.001, max: 0.009, dec: 4 }) // 0.0029

// general
faker.commerce.price({ min: 1_000_000, max: 99_000_000 }) // 3071675.85 (prices like these usually don't have decimal places)

Prices are also very often used as numbers e.g. if they are combined with quantities:

Unit Price Units Total Price
0.29 5 1.45

So commerce.price() should return number.

Summary

  • commerce.price() should return number.
  • the dec parameter should be determined automatically (unless set specifically)
  • the symbol parameter should be removed

#See also

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeCannot be merged when next version is not a major releasec: bugSomething isn't workingc: refactorPR that affects the runtime behavior, but doesn't add new features or fixes bugsm: commerceSomething is referring to the commerce modulep: 1-normalNothing urgent

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions