Because
2
and
100
are integer values, so
2 / 100
is an integer divide - and since 2 is less than 100, the result is 0.
Replace them with the floating point equivalents, and it will start to work:
public class Main
{
public static void main(String[] args) {
double price = 100.0;
double net_price = price - 2 / 100 * price;
System.out.println(price);
System.out.println(net_price);
net_price = price - 2.0 / 100.0 * price;
System.out.println(price);
System.out.println(net_price);
}
}