I want to calculate an amount, I have the amount and I have the discount percentage,
I want to use Regex.
Is there such an expression to calculate a discount amount?
I would love an example.
Can you share the document so that I can help you
Regex is used to capture text with a consistent pattern.
If you need to capture the discount percentage in a string like this:
Discount percentage: 18%
Total cost: $56
Once you obtain the amount you could calculate an amount sure.
As per @varunk’s post, please provide:
- Expected output
- Tell us what is consistent about the sample
You will have an answer soon after posting
Yes, I try to calculate the amount after discount when I have the initial amount and I know what percentage discount there is.
I searched all the forums and found nothing,
I would be happy if you could help me with the REGEX operation
We can’t provide a Regex pattern without a sample
If you want to learn Regex - check out my Regex MegaPost for new Users.
I know what REGEX is, I used it a lot to check if a variable contains letters/numbers, etc.
My question is how to use REGEX to calculate a discount.
The original amount is: $ 90
Discount is: 30%
How to do the calculation by REGEX.
It can be done in another way by:
(Original amount) * (100 / (100-discount)) Example: 0.7 * 90 then the return is the amount after discount.
Does someone have an answer?
You might want to try using Regex to capture the discount amount THEN convert the result to an integer and then do the calculation
The forum users will be happy to help you with a Regex pattern
Yes. Exactly I want it !!!
Please find the below pattern for your requirement
Now output is 18%
- It is in group1
getting the amount:
getting the discount:
getting the reduced amount
Thank you very much!!!
But there’s something I still do not understand,
Can you send me an example of an exercise,
How do you use it.
I always use REGEX like this: System.Text.RegularExpressions.Regex.
I would love for you to detail more to me.
Excellent!! It works!!!
I would love if you could check it out:
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.