Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valid number with step(scale) #476

Open
chenjuq126 opened this issue Jan 6, 2023 · 4 comments
Open

Valid number with step(scale) #476

chenjuq126 opened this issue Jan 6, 2023 · 4 comments

Comments

@chenjuq126
Copy link

chenjuq126 commented Jan 6, 2023

Condition: there are parameters(minimum, maximum, step(scale)) to valid the subject.
Validate formula: (subject - minimum)%step == 0

        String subject = "" + 0.5F;
        String minimum = "" + 0F;
        String step = "" + 0.2F;

        BigDecimal diff = new BigDecimal(subject).subtract(new BigDecimal(minimum));
        BigDecimal remain = diff.divideAndRemainder(new BigDecimal(step))[1];
        boolean equals = BigDecimal.ZERO.setScale(remain.scale()).equals(remain);

Is there any extension for NumberSchema to implement the valid?
Or other way to valid?

@chenjuq126 chenjuq126 changed the title Valid number with scale(step) Valid number with step Jan 6, 2023
@chenjuq126 chenjuq126 changed the title Valid number with step Valid number with step(scale) Jan 6, 2023
@chenjuq126
Copy link
Author

ajv supports User-defined keywords:https://ajv.js.org/guide/user-keywords.html

@erosb
Copy link
Contributor

erosb commented Jan 9, 2023

Hello, this library doesn't support custom keywords, bur maybe you can solve the problem with a custom format ?

@chenjuq126
Copy link
Author

If the step and minimum are equal for different properties, custom format is applicable.
My scenario is different. Is there any way to pass parameter(step,minimum) for each number's format step validation?

@erosb
Copy link
Contributor

erosb commented Jan 10, 2023

That isn't doable with this library, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants