Skip to content

Instantly share code, notes, and snippets.

@40823102
Last active January 2, 2020 03:35
Show Gist options
  • Save 40823102/e258ec1038576f30da81003363199f5e to your computer and use it in GitHub Desktop.
Save 40823102/e258ec1038576f30da81003363199f5e to your computer and use it in GitHub Desktop.
重量單位轉換程式
IbtoKg(num ib){
return ib*0.45;
}
KgtoIb(num kg){
return kg*2.2;
}
main() {
var type;
int len;
var number;
List temp = ["25Kg", "30Ib", "56Ib", "14Kg", "68Ib", "198Kg"];
for (var i in temp) {
len = i.length;
type = i[len-2];
number = i.substring(0, len-2);
number = int.parse(number);
if (type == "I"){
print(" $number Ib = ${IbtoKg(number).toStringAsFixed(2)} Kg");
}else{
print(" $number Kg = ${KgtoIb(number).toStringAsFixed(2)} Ib");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment