Skip to content

Instantly share code, notes, and snippets.

@suehok
Created September 1, 2023 06:23
Show Gist options
  • Save suehok/bdae9dad2645624b3dfd6af99b647694 to your computer and use it in GitHub Desktop.
Save suehok/bdae9dad2645624b3dfd6af99b647694 to your computer and use it in GitHub Desktop.
void main() {
List smartBalance(double amount){
var smartBalanceList = [];
// Exact Amount
smartBalanceList.add(amount);
int ringgitAmount = amount.truncate();
double fraction = amount - ringgitAmount;
// Nearest 50 cent
if( fraction > 0 && fraction <= 0.5 ){
if(amount < 1 ){
smartBalanceList.add(0.50);
} else {
smartBalanceList.add(ringgitAmount+0.50);
}
}
//next Ringgit Amount
smartBalanceList.add(ringgitAmount+1);
//next 5 Ringgit Amount
if(amount < 5 ){
smartBalanceList.add(5);
}else if(amount > 10 ){
int rinngitRemaining = ringgitAmount%10;
if(rinngitRemaining < 5 ){
smartBalanceList.add((ringgitAmount/10).truncate() *10 +5);
}
}
// next 10 Ringgit Amount
if(amount > 5 && amount <=10 ){
smartBalanceList.add(10);
}else if(amount > 10 ){
smartBalanceList.add((ringgitAmount/10).truncate() *10 +10);
}
// next 50 Ringgit Amount
if(amount <= 50 ){
smartBalanceList.add(50);
} else if(amount > 50 ){
smartBalanceList.add((ringgitAmount/50).truncate() *50 + 50);
}
if(smartBalanceList.length < 6){
// next 100 Ringgit Amount
if(amount <= 100 ){
smartBalanceList.add(100);
} else if(amount > 100 ){
smartBalanceList.add((ringgitAmount/100).truncate() *100 + 100);
}
}
return smartBalanceList;
}
print(smartBalance(0.20));
print(smartBalance(0.60));
print(smartBalance(1.20));
print(smartBalance(1.60));
print(smartBalance(11.20));
print(smartBalance(11.60));
print(smartBalance(61.20));
print(smartBalance(61.60));
print(smartBalance(161.20));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment