In this technical webinar, AlgoSec will present several examples of common misconfigurations; including a basic device change, business application connectivity changes, and data center migrations. Learn best practices to protect your business from attack.

It seems we have a bit of a language barrier. Maybe another voice will help?

x= (int)((a+b)*(value *(a-b)/100))

here a+b

is coming as intergervalue *(a-b)/100)

is decimalso

the second part is discarded as i am trypecasting to intBecause all of your variables are integers, all values, including the intermediate values will have an integer type. When you divide two values, the result is an integer. In your example above you divide by 100. If the divisor is between 1 and 99, you get the same result, 0. In effect, 1/100 = 99/100, for the purpose of this calculation as both result in integer 0.

To capture the fractional part of the calculation you need to determine how many decimal places you need. It's probably beyond the scope of your project to use true floating point (variable precision), so decide how many digits to the right of the decimal that you'll need. Are 2 enough? With your equation that becomes the simplest. Are 3 enough? That resolution is 1/1000.

x= (int) ((a+b)*(value *(a-b)/100))

becomes

2 decimal places -- x = ((a+b) * (value *(a-b)))

3 decimal places -- x = ((a+b) * 1000 * (value *(a-b)/100))

When you convert the value to a string, insert a decimal point 2 (or 3 places) from the right.

If you need the fractional part for future computations, just subtract it. But remember that you're using integer data types so the value is 1000 times the fraction's true value.

// Compute value * 1000

x = ((a+b) * 1000 * (value *(a-b)/100))

// Compute fractional part

frac = x % 1000;

// Restore x to the correct scale

x /= 1000;

Good Luck,

Kent