Appearance
Currency Formatter
A Service for formatting and unformatting currency values with support for both Nepali and international number systems, as well as USA and European formatting styles.
Features
- Multiple Format Types: Support for USA (dot as decimal, comma as thousand separator) and Euro (comma as decimal, dot as thousand separator) formats
- Nepali Number System: Special support for Nepali numbering system (grouping by 2 digits after the first 3)
- International Number System: Standard 3-digit grouping system
- Currency Display: Optional currency symbol display
- Bidirectional: Both formatting and unformatting capabilities
- TypeScript Support: Full TypeScript type definitions included
Types
| FormatType | StructureType |
|---|---|
| usa | nepali |
| euro | foreign |
Service Reference
CurrencyFormatter
Formats a numeric value into a currency string with the specified format and structure.
typescript
CurrencyFormatter(
value: number | string,
withDisplayCurrency?: boolean,
displayCurrency: string = "RS.",
format: FormatType = "usa",
structure: StructureType = "nepali"
): stringParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
value | number | string | - | The numeric value to format |
withDisplayCurrency | boolean | false | Whether to include currency symbol |
displayCurrency | string | "RS." | The currency symbol to display |
format | FormatType | "usa" | Number format type (usa/euro) |
structure | StructureType | "nepali" | Grouping structure (nepali/foreign) |
Returns
string - The formatted currency string
CurrencyUnformatter
Parses a formatted currency string back into a numeric value.
typescript
CurrencyUnformatter(
formattedValue: string,
withDisplayCurrency?: boolean,
displayCurrency: string = "RS.",
format: FormatType = "usa",
structure: StructureType = "nepali"
): numberParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
formattedValue | string | - | The formatted currency string to parse |
withDisplayCurrency | boolean | false | Whether the string includes currency symbol |
displayCurrency | string | "RS." | The currency symbol to remove |
format | FormatType | "usa" | Number format type (usa/euro) |
structure | StructureType | "nepali" | Grouping structure (nepali/foreign) |
Returns
number - The parsed numeric value
Usage Examples
Basic Formatting
typescript
import { CurrencyFormatter } from 'dolphin-components';
// Default Nepali format with USA style
CurrencyFormatter(1234567.89);
// Output: "12,34,567.89"
// With currency symbol
CurrencyFormatter(1234567.89, true);
// Output: "RS.12,34,567.89"
// Custom currency symbol
CurrencyFormatter(1234567.89, true, "NPR ");
// Output: "NPR 12,34,567.89"International Format
typescript
import { CurrencyFormatter } from 'dolphin-components';
// International grouping with USA format
CurrencyFormatter(1234567.89, false, "RS.", "usa", "foreign");
// Output: "1,234,567.89"
// With currency symbol
CurrencyFormatter(1234567.89, true, "$", "usa", "foreign");
// Output: "$1,234,567.89"European Format
typescript
import { CurrencyFormatter } from 'dolphin-components';
// European format with international grouping
CurrencyFormatter(1234567.89, false, "€", "euro", "foreign");
// Output: "1.234.567,89"
// With currency symbol
CurrencyFormatter(1234567.89, true, "€", "euro", "foreign");
// Output: "€1.234.567,89"Nepali Format with European Style
typescript
import { CurrencyFormatter } from 'dolphin-components';
// Nepali grouping with European decimal/thousand separators
CurrencyFormatter(1234567.89, true, "RS.", "euro", "nepali");
// Output: "RS.12.34.567,89"Unformatting Examples
typescript
import { CurrencyUnformatter } from 'dolphin-components';
// Basic unformatting
CurrencyUnformatter("12,34,567.89");
// Output: 1234567.89
// With currency symbol
CurrencyUnformatter("RS.12,34,567.89", true);
// Output: 1234567.89
// European format
CurrencyUnformatter("€1.234.567,89", true, "€", "euro", "foreign");
// Output: 1234567.89Number System Comparison
Nepali System
- Groups digits as:
XX,XX,XXX.XX - First group from right: 3 digits
- Subsequent groups: 2 digits each
- Example:
1,23,45,678.90
International System
- Groups digits as:
XXX,XXX,XXX.XX - All groups: 3 digits each
- Example:
123,456,789.01
Format Styles
USA Format
- Decimal separator:
.(dot) - Thousand separator:
,(comma) - Example:
1,234.56
Euro Format
- Decimal separator:
,(comma) - Thousand separator:
.(dot) - Example:
1.234,56
Error Handling
- Invalid numbers return empty string for formatter
- Invalid strings return
0for unformatter - Missing or null values are handled properly