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 > = 1 0 0 0 0 0 0 0 0 )
{
return ( a_amount / 1 0 0 0 0 0 0D ) . ToString ( "0.#M" ) ;
}
if ( a_amount > = 1 0 0 0 0 0 0 )
{
return ( a_amount / 1 0 0 0 0 0 0D ) . ToString ( "0.##M" ) ;
}
if ( a_amount > = 1 0 0 0 0 0 )
{
return ( a_amount / 1 0 0 0D ) . ToString ( "0.#k" ) ;
}
if ( a_amount > = 1 0 0 0 0 )
{
return ( a_amount / 1 0 0 0D ) . ToString ( "0.##k" ) ;
}
return a_amount . ToString ( "#,0" ) ;
}
}
}