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.
-l, --mathlib
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
More Posts related to MacOS,
- How to show line numbers in Nano on Mac
- How to install Jupyter Notebook on macOS Sonoma
- How to Disable Remote Management using Mac Terminal
- Test internet speed using macOS Terminal command
- Docker Desktop needs privileged access macOS
- Google Search Hot Trends Screensaver for Mac OS X
- How to do calculations in Mac Terminal
- How to make TextEdit the default text Editor on Mac
- How to Show Full Website Address on Safari for Mac (Ventura/Sonoma)
- The Zsh Shell - Mac Tutorial
- Opening mac Terminal
- How to change the name of your Mac running on macOS Ventura 13
- How to find the Battery Cycle Count on macOS Ventura
- How to set an emoji as Zsh terminal prompt in macOS
- How to access Trash Folder using Mac Terminal Command
- macOS Ventura XCode Command Line Tools Installation
- Hide Bluetooth icon on Mac Menu Bar macOS Ventura 13
- How to run .sh file in Mac Terminal
- Terminal Command to get the list of available shells in macOS
- How to see Storage Information on macOS Ventura
- How to Go To /usr/local/bin on Mac Terminal?
- How to do screen recording on Mac
- How to Find File and Directory Size in Mac Terminal
- Open .bash_profile File in TextEdit using Terminal
- Remove Now Playing icon from macOS Big Sur Menu Bar
More Posts:
- How to find Integer MAX and MIN Value in Java - Java
- Add Line Break (New Line) in Jupyter Notebook Markup Cell - Python
- How to Transpose a Square Matrix - Java Program - Java
- See actual SharePoint error exception modify web.config - SharePoint
- Mac: Sign in Required We cant upload or download your changes because your cached credentials have expired [Word Excel] - Windows
- 10 Beginners Commands for macOS Terminal Usage - MacOS
- Sort ls command by last modified date and time - Linux
- FileZilla Connection time out Failed to retrieve directory listing - FTP