# Advanced calculator with fast off-line unit converter

## Recommended Posts

Alfred unit converter is a really fast smart calculator for Alfred with support for unit conversions to make it a bit comparable to the Google Calculator and Wolfram Alpha.

If new units and/or other names for units should be added please let me know by creating an issue at:https://github.com/WoLpH/alfred-converter/issues

Example queries

```1m in cm # Just a simple conversion
2^30 byte # Using powers before conversion
5' # Converting units with special characters
20" # Like above
5 * cos(pi + 2) # Executing mathematical functions
5 * pi + 2 mm in m # Mathematical constants with unit conversion
1 * cos(pi/2) - sin(pi^2) # More advanced mathematical expressions
ln(e^10) # Testing the ln(x) alias of log _e(x)
log(e^10) # The normal log method
5+3^2" in mm # Testing math with unit conversion
1 + 2 / 3 * 4) mm^2 in cm^2 # Unbalanced paranthesis with unit conversion
((1 + 2 / 3 * 4) mm^2 in cm^2 # Unbalanced paranthesis the other way
inf - inf # Not actually possible, but we backtrack to "inf"
The list of units and conversions was downloaded from:http://w3.energistics.org/uom/poscUnits22.xml```

It returns results within 50 milliseconds making it fast enough to use the results instead of the standard alfred calculator. It supports more too

Note: the parser automatically works when you start with a number or a ".". For all other cases (functions for example) it's best to just use "=". For example: "=ln(e^5)"

Edited by wolph

##### Link to post

Very cool concept. The outputs feel a little messy, to me units is still superior (even though i'd really like it to be faster).

I really like the multiple ways to input (0 to 9, =, .) but then it lacks full blown calculator function (ln, tan, e, cos... then don't seem to work, and they can't be the first thing in because they don't start a query).

Also the precision is weird 4^.5 outputs 2.0000000000000000000000000000

##### Link to post

Really nice.

Thanks for sharing.

##### Link to post

@Florian you never know when you will need to convert square meters to miles with 19 digits of accuracy.

##### Link to post

The output can be improved indeed, for me it's a bit more convenient since it just converts it to any alternative measurement instead of just from a single one to another. Not really sure what the best solution for the output should be, right now all calculations are done with a precision of 28 places which is the default for the Decimal library. I could easily increase or decrease it upon demand. Perhaps I'll even make it configurable.

I'll see if I can make the output slightly less messy by rounding things like 4^.5

As for functions, there's actually a workaround for mathematical functions, try this for example: "=sin(pi/2)-cos(2pi)"

Very cool concept. The outputs feel a little messy, to me units is still superior (even though i'd really like it to be faster).

I really like the multiple ways to input (0 to 9, =, .) but then it lacks full blown calculator function (ln, tan, e, cos... then don't seem to work, and they can't be the first thing in because they don't start a query).

Also the precision is weird 4^.5 outputs 2.0000000000000000000000000000

Edited by wolph

##### Link to post

@Florian you never know when you will need to convert square meters to miles with 19 digits of accuracy.

Yeah... it's nice to have accuracy but sometimes it's a bit much

Right now it rounds to 6 decimal places so things like 4^.5 work without a problem but it doesn't lose precision for calculations like: (25/4)^.5

##### Link to post

Very cool concept. The outputs feel a little messy, to me units is still superior (even though i'd really like it to be faster).

Can't say I saw the units library before I started writing this, that's indeed a lot better. I was previously trying to use the units library from Jason Cheatham which never worked the way I liked.

The one thing I don't like about the units library is that it requires an internet connection, otherwise it just fails. By doing everything locally it always (on my system at least) return within 50ms making it fast enough for instant results.

Either way, I think I've fixed all issues (although it's not as pretty as the units library). Perhaps I can merge some things with the units library, can't find any license information though.

##### Link to post

Very cool concept. The outputs feel a little messy, to me units is still superior (even though i'd really like it to be faster).

I really like the multiple ways to input (0 to 9, =, .) but then it lacks full blown calculator function (ln, tan, e, cos... then don't seem to work, and they can't be the first thing in because they don't start a query).

Also the precision is weird 4^.5 outputs 2.0000000000000000000000000000

If you're willing to try again. I've included some icons in the output to make everything a bit clearer. Perhaps that helps

##### Link to post

Added support for binary, octal and hexadecimal numbers

##### Link to post

Loving this workflow!

In my daily work I add a lot of prices, sometimes 10+ numbers together. I see that if you leave a space between numbers it will multiply them together

(wouldn't let me embed image)

http://r.roccit.com/1539j

Is it possible to edit the script somewhere to make the default operation in this case be addition?

Here's to saving my pinky finger

-roccit

##### Link to post

Right now it's just using the mathematical method of calculating (which means that `(5)(6)` will default to multiplying). And as a side-effect, spaces also multiply I guess

To change this to addition instead of multiplying you just need to replace the * with a + over here: https://github.com/WoLpH/alfred-converter/blob/master/converter/safe_math.py#L25

##### Link to post

Thanks for the reply. Not sure I want to sacrifice that default behavior, but now I play with it

Works

http://r.roccit.com/12aIB

##### Link to post

Just noticed that when I press return after an operation the answer is not being copied to the clipboard. Deleted and re-loaded the WF and it's still not working. Something else I need to turn on?

##### Link to post

That's weird... it works just fine for me, can you try with this release (I've just uploaded it):

##### Link to post

Odd. Works fine now. Thanks!

##### Link to post

I need to convert height in feet/inches to cm/meters. Can't figure out how to do that. I'd like to type e.g. 6'1 or 6'1" but doesn't seem to work. Anyone smarter than me?

##### Link to post

That's currently not directly supported, but it's easy to work around it. Just type "6' in inch" followed by a tab, it will give you the size in inches straight away. After that you can simply add them

I've added it to the todo: https://github.com/WoLpH/alfred-converter/issues/5

##### Link to post
On 12/16/2015 at 4:54 AM, simongade said:

I need to convert height in feet/inches to cm/meters. Can't figure out how to do that. I'd like to type e.g. 6'1 or 6'1" but doesn't seem to work. Anyone smarter than me?

You can do that with this workflow with the simple query "units 5'7" cm"

##### Link to post

Hello,

Really amazing workflow!

Just one question how to count percentages?

I want to count these functions, examples:

Calculate a percentage of a number:

15% of 80

Calculate a percentage of a quantity:

7.5% of \$12.95

Increase a quantity by a percentage:

\$2400 + 15%

Compute a discounted price:

15% off of \$29.95

##### Link to post
1 hour ago, blacksnow said:

Just one question how to count percentages?

@Tyler Eich wrote a workflow just for that here:

But generally you use multiplication and decimal fractions instead:

15% of 80 is 80 * .15

7.5% of 12.95 is 12.95 * .075

2400 + 15% is 2400 * 1.15

15% off 29.95 is 29.95 * .85

##### Link to post

Percentages were already somewhat supported but not in the way you're currently using them. Currently they're only part of ratios (i.e. parts per million)

I've created a new version that supports pretty much all of this but it ignores the \$ sign since there's no currency support yet.

##### Link to post
15 minutes ago, wolph said:

Percentages were already somewhat supported but not in the way you're currently using them. Currently they're only part of ratios (i.e. parts per million)

I've created a new version that supports pretty much all of this but it ignores the \$ sign since there's no currency support yet.

Wow that was as quick as could possible be. Works perfectly just tested! Thank you so much.

And I am sorry for not telling this at the beginning but few more percentage features would be nice:

Examples:

15 is what percent of 130?

What is the percentage increase/decrease? From 98 to 60

##### Link to post

I've implemented a version of it but I have to be careful not to break anything else.

The syntax is "... to/from/diff/difference/change ..." and "... percentage of ..."

##### Link to post

Once again works like a charm. Thanks so much!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.