Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working as a salesman and what I need to do a lot of times a day is calculating the price +VAT and -VAT which is 19% here in Germany. I found some calculation automator script but wasn't able to change it to behave the way I want it to:

bc --mathlib | awk '{if($0 ~ /./) sub("\.+$","");print}'

this, ran as a shell script, takes operations so for example (somewhere) I type in the price 100*1.19, select it with the mouse and run the service. It then calculates the operation and replaces the selected text with the result 119.

But I only want to select the 100 and hit one of the services +VAT or -VAT (in the contextual menu for example) and it will be replaced by the result. That would be so awesome.

Is there anyone that can help? Maybe with a Applescript or something! Thanks very much!

share|improve this question
up vote 1 down vote accepted

n =[0-9., ]+/)[0]
separator = "."
separator = "," if n =~ /.+[. ].+,.+/ || n =~ /,/ && n !~ /\./
separator == "." ? n.gsub!(/[, ]/, "") : n = n.gsub(/[. ]/, "").gsub(",", ".")
out = "%.02f" % ((n.to_f * 1.19 * 100).round.to_f / 100)
out.gsub!(".", ",") if separator == ","
print out
  • Understands both 10,000.50 and 10.000,50, but treats 10,000 and 10.000 as 10
  • Half decimals are rounded up, negative half decimals down
share|improve this answer
WOW, that was fast! But it does only recognize 99.99 not 99,99. Is it possible, to get it a) read with comma and b) replaces out with comma? (best way would be output like input!) – Thron Jan 31 '12 at 14:24
@Thron You're right, I edited the script... It should now round numbers correctly as well. – user495470 Jan 31 '12 at 17:05
I wish I could upvote this question and answer more than once. Services are such an amazing feature of Mac OS X, and this use case illustrates why. – Daniel Jan 31 '12 at 17:09
This is so unbelievable awesome... Thank you so much! – Thron Jan 31 '12 at 17:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.