mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-03-10 04:51:47 +00:00
feat: adição de novos ícones SVG e configuração do ambiente
- Adicionados ícones SVG para ChatGPT, Claude, Gemini e OpenRouter - Implementados ícones para modos claro e escuro do ChatGPT - Criado script de inicialização para PostgreSQL com extensão pgcrypto - Adicionado script de configuração de ambiente que faz backup do .env - Configurado tsconfig.json para TypeScript com opções de compilação
This commit is contained in:
60
lib/utils/currency.ts
Normal file
60
lib/utils/currency.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Utility functions for currency/decimal formatting and parsing
|
||||
*/
|
||||
|
||||
/**
|
||||
* Formats a decimal number for database storage (2 decimal places)
|
||||
* @param value - The number to format
|
||||
* @returns Formatted string with 2 decimal places, or null if input is null
|
||||
*/
|
||||
export function formatDecimalForDb(value: number | null): string | null {
|
||||
if (value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (Math.round(value * 100) / 100).toFixed(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a decimal number for database storage (non-nullable version)
|
||||
* @param value - The number to format
|
||||
* @returns Formatted string with 2 decimal places
|
||||
*/
|
||||
export function formatDecimalForDbRequired(value: number): string {
|
||||
return (Math.round(value * 100) / 100).toFixed(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes decimal input by replacing comma with period
|
||||
* @param value - Input string
|
||||
* @returns Normalized string with period as decimal separator
|
||||
*/
|
||||
export function normalizeDecimalInput(value: string): string {
|
||||
return value.replace(/\s/g, "").replace(",", ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a limit/balance input for display
|
||||
* @param value - The number to format
|
||||
* @returns Formatted string or empty string
|
||||
*/
|
||||
export function formatLimitInput(value?: number | null): string {
|
||||
if (value === null || value === undefined || Number.isNaN(value)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return (Math.round(value * 100) / 100).toFixed(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an initial balance input for display (defaults to "0.00")
|
||||
* @param value - The number to format
|
||||
* @returns Formatted string with default "0.00"
|
||||
*/
|
||||
export function formatInitialBalanceInput(value?: number | null): string {
|
||||
if (value === null || value === undefined || Number.isNaN(value)) {
|
||||
return "0.00";
|
||||
}
|
||||
|
||||
return (Math.round(value * 100) / 100).toFixed(2);
|
||||
}
|
||||
Reference in New Issue
Block a user