I'm trying to add two values. When adding money it very simple when its 50p+20p=70p. But if I add £1 then I face a problem because 70+1=71 wrong. So I tried to enter £1 as 100p so I have 170p. But here the problem I want to output it as £1.70 instead. So if I divide 170 by 100 I get 1.70
But here yet another problem. I divided the total by 100. So now when I enter 30p it adds to 1.70+30=31.70 (wrong again).
So my approach with dividing by 100 didn't work. So I decided to divide the total only if the inserted amount is greater than 100 and the total as well. It stil didn't work.
So I decided to use double instead. So if I want to insert 50p I would write 0.50. But now this time the problem with this is that when I add 0.50 it is displayed as 0.5 ( I want to display it as 0.50). And in other example, instead of 0.15 the result usually displays something like this eg.0.1500000000 0000002.
So, how can I make this value (0.150000000000 00002) and display it as 0.15?
And how can I make this value (0.5) and display it as 0.50?
Regards,
John
But here yet another problem. I divided the total by 100. So now when I enter 30p it adds to 1.70+30=31.70 (wrong again).
So my approach with dividing by 100 didn't work. So I decided to divide the total only if the inserted amount is greater than 100 and the total as well. It stil didn't work.
So I decided to use double instead. So if I want to insert 50p I would write 0.50. But now this time the problem with this is that when I add 0.50 it is displayed as 0.5 ( I want to display it as 0.50). And in other example, instead of 0.15 the result usually displays something like this eg.0.1500000000 0000002.
So, how can I make this value (0.150000000000 00002) and display it as 0.15?
And how can I make this value (0.5) and display it as 0.50?
Regards,
John
Comment