I’m trying to make a script that will allow me to enter a cost, apply a VAT percentage to it, apply a mark-up to this total and then show the final grand total.
Essentially the sum that I’m trying to do is this:
Cost + VAT¹ + Mark-up cost² = Total
1 - To be entered by the user
2 - To be entered by the user
The problem is that the math isn’t currently working.
What should be happening is that the first number, eg: 100 (entered into dialog box 2) should then have a percentage of VAT added (eg: 20 for 20% - added into dialog box 3) followed by a markup of an amount entered into dialog box 4, (eg: 10 for 10%) which should lead the final dialog box to display 132 instead it’s displaying 20000.
I’m dyslexic so math was never my strong suite, but I’m stumped as to how to fix this, (although I bet it’s really simple!).
If you want exactly the displayed string, add the line
set the clipboard to totalCost
before the last display dialog line.
If you want only the value, replace the part after the 4 comment lines with
.
tell num1 * (100 + num2) * (100 + num3) / 100 to ¬
tell (it div 0.5 - it div 1) to ¬
tell it div 100 & "." & text 2 thru 3 of (100 + it mod 100 as text) to set {totalCostString, totalCost} to {"Total Cost to Client: £" & it, "" & it}
set the clipboard to totalCost
display dialog totalCostString buttons {"Thanks!"} default button {"Thanks!"} --displays the equation and calculates the answer
end if
Just a bit playing with Nigel’s amazing “tell chain”
Yes of course you can. And sorry for this slow response. My own distraction is caring for an elderly mother.
Phew! It makes me feel a bit dyslectic myself!
You may recall that (100 + num2) is notionally divided by 100 too, but that I cancelled out the division against the multiplication of the end result by 100 prior to rounding. It turns out that (100 + num3)'s division by 100 can be included in the rounding by using larger divisors for that, giving the slightly simpler but even more opaque:
.
tell num1 * (100 + num2) * (100 + num3) to ¬
tell (it div 50 - it div 100) to ¬
tell it div 100 & "." & text 2 thru 3 of (100 + it mod 100 as text) to set {totalCostString, totalCost} to {"Total Cost to Client: £" & it, "" & it}
set the clipboard to totalCost
display dialog totalCostString buttons {"Thanks!"} default button {"Thanks!"} --displays the equation and calculates the answer
end if
Having blindly copied the last comment in the script a couple of times, I’ve just noticed it’s wrong!