I have a code that rounds a value of type decimal
to homes I want, and I would like to implement it in Android in Java but I'm having some difficulties, here's the code below in C #.
public static class Valor
{
public static decimal Arredondar(decimal valor, int casasDecimais)
{
var valorNovo = decimal.Round(valor, casasDecimais);
var valorNovoStr = valorNovo.ToString("F" + casasDecimais, CultureInfo.CurrentCulture);
return decimal.Parse(valorNovoStr);
}
public static decimal? Arredondar(decimal? valor, int casasDecimais)
{
if (valor == null) return null;
return Arredondar(valor.Value, casasDecimais);
}
}
As I researched I would have to use Bigdecimal
but I'm having several problems.