Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

add floating point calculation functions #3

Description

@icasimpan

c/o https://tecadmin.net/bash-floating-point-math-calculations/

Addition/ Subtraction

num1=3.14
num2=1.73
 
# Addition
result=$(echo "scale=2; $num1 + $num2" | bc)
echo "Addition: $result"
 
# Subtraction
result=$(echo "scale=2; $num1 - $num2" | bc)
echo "Subtraction: $result"

Multiplication/Division

num1=5.25
num2=2.5
 
# Multiplication
result=$(awk "BEGIN { printf(\"%.2f\", $num1 * $num2) }")
echo "Multiplication: $result"
 
# Division
result=$(awk "BEGIN { printf(\"%.2f\", $num1 / $num2) }")
echo "Division: $result"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions