Need to display numbers correctly for users worldwide? This guide covers everything you need to know about formatting numbers for different locales via API, including thousands separators, decimal places, and implementation examples in multiple languages.
What is Number Formatting?
Number formatting is the process of converting raw numbers into human-readable strings with appropriate separators, decimal places, and notation based on locale preferences.
For example, the number 1234567.89 formats as "1,234,567.89" in US English, "1.234.567,89" in German, and "12,34,567.89" in Indian English.
Locale Differences
Different regions use different number formatting conventions:
US/UK (en-US, en-GB)
Comma thousands separator, period decimal: 1,234,567.89
Germany/France (de-DE, fr-FR)
Period thousands separator, comma decimal: 1.234.567,89
India (en-IN)
Lakhs/crores grouping: 12,34,567.89 (12 lakhs, 34 thousand)
Using the Number Format API
TinyFn provides a simple endpoint to format numbers:
GET https://api.tinyfn.io/v1/format/number?value=1234567.89&locale=en-US
Headers: X-API-Key: your-api-key
{
"value": 1234567.89,
"formatted": "1,234,567.89",
"locale": "en-US",
"options": {
"minimumFractionDigits": 2,
"maximumFractionDigits": 2
}
}
Parameters
| Parameter | Type | Description |
|---|---|---|
value |
number | The number to format |
locale |
string | Locale code: en-US, de-DE, fr-FR, etc. (default: en-US) |
minimumFractionDigits |
integer | Minimum decimal places (default: 0) |
maximumFractionDigits |
integer | Maximum decimal places (default: 3) |
notation |
string | Notation style: standard, scientific, engineering, compact |
Code Examples
JavaScript / Node.js
// Format number for US locale
const response = await fetch(
'https://api.tinyfn.io/v1/format/number?value=1234567.89&locale=en-US',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const { formatted } = await response.json();
console.log(formatted); // 1,234,567.89
// Format for German locale
const deResponse = await fetch(
'https://api.tinyfn.io/v1/format/number?value=1234567.89&locale=de-DE',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const { formatted: deFormatted } = await deResponse.json();
console.log(deFormatted); // 1.234.567,89
Python
import requests
# Format for US locale
response = requests.get(
'https://api.tinyfn.io/v1/format/number',
params={'value': 1234567.89, 'locale': 'en-US'},
headers={'X-API-Key': 'your-api-key'}
)
print(response.json()['formatted']) # 1,234,567.89
# Format for German locale
response = requests.get(
'https://api.tinyfn.io/v1/format/number',
params={'value': 1234567.89, 'locale': 'de-DE'},
headers={'X-API-Key': 'your-api-key'}
)
print(response.json()['formatted']) # 1.234.567,89
cURL
# Format for US locale
curl "https://api.tinyfn.io/v1/format/number?value=1234567.89&locale=en-US" \
-H "X-API-Key: your-api-key"
# Format for German locale
curl "https://api.tinyfn.io/v1/format/number?value=1234567.89&locale=de-DE" \
-H "X-API-Key: your-api-key"
Common Use Cases
- E-commerce: Display prices and quantities correctly for each market
- Analytics Dashboards: Format statistics for international users
- Financial Applications: Show account balances in local format
- Report Generation: Create locale-appropriate reports
- Data Export: Format numbers for regional spreadsheets
Best Practices
- Detect user locale: Use Accept-Language header or user preferences
- Be consistent: Use the same formatting throughout your application
- Handle edge cases: Very large or very small numbers may need scientific notation
- Test thoroughly: Verify formatting for all supported locales
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-format": {
"url": "https://api.tinyfn.io/mcp/format/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all formatting tools available via MCP in our Formatting MCP Tools for AI Agents guide.
Try the Number Format API
Get your free API key and start formatting numbers internationally in seconds.
Get Free API Key