Otter Snippets Otter Upstream Otter 1.0.1 Tested

Format Number as Currency

Format a numeric amount into a currency string with 2-decimal precision.

ID: snippet/conv-number-format Version: 1.0.0 License: MIT Framework: Otter 1.0.1

Architecture & Runtime Preview

Otter 1.0.1

Zero-dependency Otter 1.0.1 snippet (Math & Numbers). Copy the parameterized template or run the self-contained example.

  1. 1Category: Math & Numbers
  2. 2Attribution: Otter Reusable Library (Official)
  3. 3Zero external pack dependencies — paste directly into any .ot file

Source Code (2 files)

template.ot · otter
to formatCurrency amount
    parts are
        amount
    .
    join parts with "" into amountStr
    if amountStr contains "."
        split amountStr by "." into decParts
        whole is first of decParts
        cents is last of decParts
        if length of cents is 1
            cents is cents plus "0"
        .
        outParts are
            "$"
            whole
            "."
            cents
        .
        join outParts with "" into result
        return result
    otherwise
        outParts are
            "$"
            amountStr
            ".00"
        .
        join outParts with "" into result
        return result
    .
.

Installation & Usage

otter snippet inspect conv-number-format

Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.