If you are wondering which command line utility to use on your Mac Terminal to do arithmetic calculations such as addition, subtraction or multiplication then you can make use of bc - An arbitrary precision calculator language, it ships with your macOS.
% man bc bc(1) bc(1) NAME bc - An arbitrary precision calculator language SYNTAX bc [ -hlwsqv ] [long-options] [ file ... ] VERSION This man page documents GNU bc version 1.06. DESCRIPTION bc is a language that supports arbitrary precision numbers with inter- active execution of statements. There are some similarities in the syntax to the C programming language. A standard math library is available by command line option. If requested, the math library is defined before processing any files. bc starts by processing code from all the files listed on the command line in the order listed. After all files have been processed, bc reads from the standard input. All code is executed as it is read. (If a file contains a command to halt the processor, bc will never read from the standard input.)
Lets see some examples:
code2care@mac ~ % bc bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 20+10+30 60 a=10 b=20 a+b 30 (a+b)*100 3000 (10/20)*100 0
You can see that the division came out to be incorrect, that because the result is truncated to an integer, you would need to use the -l option to work with floats.
Define the standard math library
code2care@mac ~ % bc -l bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. (10/20)*100 50.00000000000000000000
- How to find files taking up space on your Mac
- How to open new tabs macOS Terminal
- Encode or Decode Base64 String using Mac Terminal Command
- How to take a screenshot on a Mac? (updated for macOS Monterey 2022)
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required.
- How to know your Mac Screen Resolution?
- How to make macOS Terminal window Transparent (or Opaque)
- [macOS] Change homepage Macbook Safari Browser
- Cut, Copy and Paste keyboard commands on mac
- Shutdown Mac Terminal Command
- Zsh Shell: Custom alias that you may find useful
- How to uninstall GarageBand from Mac
- How to Refresh Mac Desktop
- How to fix command not found brew (bash, zsh) on macOS Terminal
- How to Right Click on Mac Desktop?
- How to remove app from Dock when closed [macOS Big Sur]
- How to display directory tree in Mac Terminal
- [Eclipse] Locate Preferences in macOS
- How to save webpage as pdf using macOS Safari
- Set Python 3.8 as a default python version on macOS
- 10 Beginners Commands for macOS Terminal Usage
- Display Seconds in Digital Clock on Mac Menu Bar [macOS]
- [Solution] macOS Big Sur Installation: There is not enough free space, Additional Space Required
- How to search (find) in macOS Terminal Console Text
- How to come out of dquote prompt in Terminal - macOS/Linux
- 97 Useful Notepad++ Keyboard Shortcuts - NotepadPlusPlus
- How to save IntelliJ IDE Console logs to external log file - Android-Studio
- [Fix] Modern authentication failed here, but youll still be able to sign in. Your status code is 4c7 - Microsoft Teams - Teams
- Change Android EditText Cursor Height - Android
- Quick steps to install Nginx on Ubuntu Linux - Ubuntu
- Update SharePoint Online List Item using REST API, HTML, Spfx, Postman - SharePoint
- How to make jsfiddle bootstrap ready - CSS