Skip to content

Função converterMoedaParaDouble retornar 0 quando em branco #83

@lucasmiranda5

Description

@lucasmiranda5

Olá acho que seria mais interessante na função converterMoedaParaDouble se o valor for igual a vazio retornar o valor de 0 em vez de retornar um error,

static double converterMoedaParaDouble(String valor) {
    assert(valor.isNotEmpty);
    final value = double.tryParse(
        valor.replaceAll('R\$ ', '').replaceAll('.', '').replaceAll(',', '.'));

    return value ?? 0;
  }

Seria transformar esse código acima em

double converterMoedaParaDouble(String valor) {
    if (valor.isEmpty) return 0;
    final value = double.tryParse(valor.replaceAll('R\$ ', '').replaceAll('.', '').replaceAll(',', '.'));

    return value ?? 0;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions