Comments (6)
Take a look at RandomService class. Initially I didn't think it would be useful to have it public since mostly what it does is wrapping around java.util.Random
. But I don't see any reason not to expose it from Faker
class, for example, if it can be useful.
You could do something like:
val intAmount = faker.randomService.nextInt(1, 100) // returns a random int from 1 to 100
val moneyAmount = "$$intAmount"
Different monetary signs like $
, €
, ¥
, et al., can be supported through a separate function if that's of any interest as well.
from kotlin-faker.
Hi.
Can you give an example of what function you are calling and what output you expect?
from kotlin-faker.
Some function that can help creating random amount.
So is something like this possible?
faker.amount(Locale.US) - $123,312,123
from kotlin-faker.
Thanks for this but i think I will have to end up using a currency formatter that formats the value correctly because in the end the result should look something like this $125,212,212.04
from kotlin-faker.
A random number with a floating point can also be generated by RandomService
class.
But from what I understood, you also need a "thousands separator" (in your example it's a ,
but I think it should be configurable as well) ?
In that case a new function can be added (probably to Finance provider, unless I find a better place for it), that puts all of this together.
from kotlin-faker.
Closed with 2e3daea
@kdani41 FYI.
For now only $
currency sign is supported irrespective of selected locale. This can be further enhanced to support locale-based currency signs, which only requires changes to the localized yml dict files. Feel free to make a PR or open another issue for that.
from kotlin-faker.
Related Issues (20)
- When creating class instance I would like to prepend string values with the name of the property (feature request) HOT 12
- Add context when newInstance() fails HOT 4
- Crashes in Jetpack Compose previews HOT 1
- Move to java17 as default
- Cannot generate valid en-GB postcode HOT 7
- Remove SLF4J HOT 1
- Getting 'ClassCastException' when using kotlin-faker with Generics Type HOT 9
- Postal Code for CA/UK returns regex, not an actual Postal Code HOT 5
- Add blns
- Add rendering for sub-provider functions in cli
- Make it possible to lookup providers by name in cli
- Improve integration tests
- Allow RandomClassProvider::randomClassInstance to use predefinedGenerators from config if present HOT 4
- RandomClassProvider doesn't handle constructorless types correctly in all instances HOT 1
- Allow random to be used with unique HOT 1
- Regexify generates invalid value HOT 2
- Regexify should take Regex as an argument HOT 1
- Regexify fails with StackOverflowError HOT 5
- random.nextLong(bound: Long) also returns negative values HOT 3
- Suggestion: internet.ipv4() and internet.ipv6() HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlin-faker.