Menu

Peso Pricing Without Tears: Money Math for Philippine Reseller Tools
📰

Peso Pricing Without Tears: Money Math for Philippine Reseller Tools

DEV Community: python·SEO - NT Tech Innovation·3 days ago
#fRZ67Qd9
#devtopython#devto#dev#decimal#rounding
Reading 0:00
15s threshold

If you build tools for Filipino sellers, sooner or later you hit a boring but sneaky problem. Money math.

Supplier rates come in one currency, often with four or five decimal places. Your customers want clean peso prices. And somewhere between the two, rounding errors quietly eat your margin.

Here's how I'd handle peso pricing in a small reseller or SMM tool.

Rule 1: never use floats for money

>>> 0.1 + 0.2 0.30000000000000004

Enter fullscreen mode

Exit fullscreen mode

Fine for physics. Terrible for invoices. Use Decimal in Python (or integer centavos everywhere).

from decimal import Decimal , ROUND_HALF_UP , ROUND_CEILING

def to_peso ( value ) -> Decimal : return Decimal ( str ( value )). quantize ( Decimal ( " 0.01 " ), rounding = ROUND_HALF_UP )

Enter fullscreen mode

Exit fullscreen mode

Rule 2: prices are per 1,000, orders aren't

Most social media service APIs quote a rate per 1,000 units. Customers order 250, 1,500 or 3,333.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.