In Blnk, balances are stored as integers, while transaction amounts are accepted as float. To correctly compute your balance, transaction amounts have to be stored as integers as well. This ensures that your ledger is accurate.

What is precision?

Blnk uses precision to convert your transaction amounts into the lowest unit possible for their asset class, e.g. converting Dollar to cents.

Let’s dive in ✨

What we’ll cover …

  1. Why use precision
  2. Applying precision
  3. Best practices

1. Why use precision

Precision is crucial because computers are not great at storing and managing floating points as best as Blnk needs it to. Learn more: Floating Point Math.

For instance, if a customer sends 1000.50 to a vendor, Blnk accepts the amount value as 1000.50 (float), retrieves the defined precision (e.g. 100), and applies it to the amount. This converts our amount from 1000.50 to 100050.

This ensures that all amounts are accounted for when computing the balances, and we can accurately store amounts without dealing with the technical issues of managing floating points.

2. Applying precision

To set precision on your transaction, the precision field must be passed while recording a transaction. The default value, if not passed, is set to 1.

Consider the following sample request:

Request
{
    "amount": 750.23,
    "reference": "ref_001adcfgf",
    "currency": "USD",
    "precision": 100,
    "source": "bln_28edb3e5-c168-4127-a1c4-16274e7a28d3",
    "destination": "bln_ebcd230f-6265-4d4a-a4ca-45974c47f746",
    "description": "For fees",
    "meta_data": {
      "sender_name": "John Doe",
      "sender_account": "00000000000"
    }
}

Determining your precision value

When recording a transaction with a particular asset class (e.g., USD), determine the lowest possible amount and choose a precision value that ensures that the amount is converted to the lowest unit possible.

Sample asset classLowest possible amountSuggested precision valueLowest unit to be stored
GBP0.011001
USD0.011001
BTC0.000000011000000001
ETH0.000000000000000000110000000000000000001

Standardize precision across currencies: Use the highest precision value when managing currencies with different precisions, like crypto and fiat. This ensures accurate transactions and consistent exchange rate calculations.

We created an open source repository of all 151 fiat currencies and their respective precision values. See here:

Here’s the response from our request earlier:

Response
{
    "id": "txn_6164573b-6cc8-45a4-ad2e-7b4ba6a60f7d",
    "source": "bln_28edb3e5-c168-4127-a1c4-16274e7a28d3",
    "destination": "bln_ebcd230f-6265-4d4a-a4ca-45974c47f746",
    "reference": "ref_001adcfgf",
    "amount": 750.23,
    "precision": 100,
    "precise_amount": 75023,
    "currency": "USD",
    "description": "For fees",
    "status": "QUEUED",
    "created_at": "2024-02-20 05:28:03 UTC",
    "meta_data": {
      "sender_name": "John Doe",
      "sender_account": "00000000000"
    }
}

We save the provided amount in float and calculate the precise_amount using the provided precision value (amount * precision). We use the precise_amount to compute your ledger balances.

When retrieving balances to display in your application, you can always convert back to the primary asset class by dividing with the precision value.

3. Best practices

  1. Consistency: It is very crucial to maintain consistency in how precision is applied in your application.

    • Transactions with the same currency should have the same precision applied to its amounts across your application.
    • Ensure that your precision value converts the target amount to the lowest unit possible. For example, while “100” converts most fiat currencies to their lowest unit, crypto currencies like Bitcoin can have up to “100000000” as their precision value.
  2. Review and audit: Regularly review and audit you ledger to ensure that precision is applied consistently and correctly.

  3. Ensure correctness: Confirm that all currencies in your ledger use the same precision value. This is especially important if money moves between balances with different currencies (e.g., GBP and USD, or BTC and USDT).

Why consistency matters

  1. Accuracy: Consistent use of precision ensures that all transaction amounts and balances are accurately represented in your Blnk Ledger, preventing calculation errors, where applicable.

  2. Comparability: Transactions and balances with the same precision are directly comparable, simplifying financial analysis and reporting.

  3. Integrity: Maintaining a uniform approach to precision preserves the integrity of your Blnk Ledger, making it more reliable and trustworthy for other financial operations.

Need help?

We are very happy to help you make the most of Blnk, regardless of whether it is your first time or you are switching from another tool.

To ask questions or discuss issues, please contact us or join our Discord community.

Get access to Blnk Cloud.

Manage your Blnk Ledger and explore advanced features (access control & collaboration, anomaly detection, secure storage & file management, etc.) in one dashboard.

Was this page helpful?