Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from jradelmo/master
Adicionar extensores aos tipos double e int
- Loading branch information
Showing
3 changed files
with
130 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:intl/intl.dart'; | ||
|
||
extension BrasiLFields on double { | ||
/// Converte um valor double para centavos com o símbolo de real brasileiro | ||
String get obterCentavos => '${this < 0 ? '-' : ''}R\$ ${(abs() * 100).toInt().toString()}'; | ||
|
||
/// Converte um valor double para centavos sem o símbolo de real brasileiro | ||
/// | ||
String get obterCentavosSemSimbolo => obterCentavos.replaceAll('R\$ ', ''); | ||
|
||
/// Converte um valor double para real com o símbolo de real brasileiro | ||
/// | ||
/// [fracaoDigitos] define a quantidade de casas após a vírgula | ||
String obterReal([int fracaoDigitos = 2]) => NumberFormat.currency(locale: 'pt_BR', decimalDigits: fracaoDigitos, symbol: 'R\$').format(this); | ||
|
||
/// Converte um valor double para real com o símbolo de real brasileiro | ||
/// | ||
/// [fracaoDigitos] define a quantidade de casas após a vírgula | ||
String obterRealSemSimbolo([int fracaoDigitos = 2]) => obterReal(fracaoDigitos).replaceAll('R\$ ', ''); | ||
} | ||
|
||
extension BrasilFields on int { | ||
/// Converte um valor inteiro para centavos com o símbolo de real brasileiro | ||
String get obterCentavos => '${this < 0 ? '-' : ''}R\$ ${(abs() * 100).toInt().toString()}'; | ||
|
||
/// Converte um valor inteiro para centavos sem o símbolo de real brasileiro | ||
/// | ||
String get obterCentavosSemSimbolo => obterCentavos.replaceAll('R\$ ', ''); | ||
|
||
/// Converte um valor inteiro para real | ||
/// | ||
/// [fracaoDigitos] define a quantidade de casas após a vírgula | ||
String obterReal([int fracaoDigitos = 2]) => NumberFormat.currency(locale: 'pt_BR', decimalDigits: fracaoDigitos, symbol: 'R\$').format(this); | ||
|
||
/// Converte um valor inteiro para real com o símbolo de real brasileiro | ||
/// | ||
/// [fracaoDigitos] define a quantidade de casas após a vírgula | ||
String obterRealSemSimbolo([int fracaoDigitos = 2]) => obterReal(fracaoDigitos).replaceAll('R\$ ', ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters