You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.8 KiB
63 lines
1.8 KiB
using Biskilog_Accounting.Shared.Interfaces;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Biskilog_Accounting.Shared.ServiceRepo
|
|
{
|
|
public class CalculatorService : ICalculator
|
|
{
|
|
public double CalculatePercentage()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public string FormatMoneyWithCurrency(double a_amount)
|
|
{
|
|
return string.Format(GetCurrencyCode(), " {0:C2}", a_amount);
|
|
}
|
|
public string FormatMoneyWithCurrencyKilo(double a_amount)
|
|
{
|
|
return GetCurrencyCode().CurrencySymbol + FormatNumber(a_amount);
|
|
}
|
|
public NumberFormatInfo GetCurrencyCode()
|
|
{
|
|
//TODO have a better implementation
|
|
|
|
// Specify the locale for Ghana
|
|
string locale = "en-GH";
|
|
|
|
// Get the NumberFormatInfo for the specified locale
|
|
NumberFormatInfo numberFormatInfo = new CultureInfo(locale).NumberFormat;
|
|
|
|
// Set the currency symbol to Ghanaian cedi
|
|
numberFormatInfo.CurrencySymbol = "GH₵ ";
|
|
|
|
return numberFormatInfo;
|
|
}
|
|
private string FormatNumber(double a_amount)
|
|
{
|
|
if (a_amount >= 100000000)
|
|
{
|
|
return (a_amount / 1000000D).ToString("0.#M");
|
|
}
|
|
if (a_amount >= 1000000)
|
|
{
|
|
return (a_amount / 1000000D).ToString("0.##M");
|
|
}
|
|
if (a_amount >= 100000)
|
|
{
|
|
return (a_amount / 1000D).ToString("0.#k");
|
|
}
|
|
if (a_amount >= 10000)
|
|
{
|
|
return (a_amount / 1000D).ToString("0.##k");
|
|
}
|
|
|
|
return a_amount.ToString("#,0");
|
|
}
|
|
}
|
|
}
|
|
|