Subtraction result with double many decimal places appear

Asked

Viewed 41 times

-1

I’m starting at Dart and went to perform a simple subtraction operation with double but the result is very strange. For example in a subtraction of a salary of 3000 minus the ceiling of inss of 2089.60 the result would be 910.40. When I do the print aparece 910.4000000000001.

this is the code

void main() {
  
  double salMin = 1045.00;
  double vlSalario = 3000.00;
  
  double tetoInss1 = 2089.60;
  double tetoInss2 = 3134.4;
  double tetoInss3 = 6101.06;
  
  double fxCont2 = 1044.59;
  double fxCont3 = 1044.79;
      
  double primFaixa;
  if(vlSalario > salMin && vlSalario <= tetoInss1){
    primFaixa = vlSalario - salMin;
  } else{
    primFaixa = salMin;
  }
  
  double seguFaixa;
  if(vlSalario > tetoInss1 && vlSalario <= tetoInss2){
    seguFaixa = vlSalario - tetoInss1;
  } else if(vlSalario > tetoInss2){
    seguFaixa = fxCont2;
  }
  
  double tercFaixa;
  double quarFaixa;
  
  print(primFaixa);
  print(seguFaixa);
}

Erro ao gerar subtração

  • And your doubt? What is? EDITA your question making it clearer what you want.

  • https://answall.com/q/219211/101

1 answer

1


String toStringAsFixed(int fractionDigits)
Returns a decimal-point string-representation of this.

Return a decimal representation of the string type, where fractionDigits is the number of decimal places.

print(primFaixa.toStringAsFixed(2));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.