Advertisement
BladeMechanics

Kefa Ngunjiri

Jan 29th, 2021
1,337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.85 KB | None | 0 0
  1. //run this in https://dartpad.dev
  2. void main() {
  3.   //I'm assuming you saved the data in this form
  4.   var myGift = {"value": 1};
  5.   print(myGift);
  6.   //so I'm also seeing a problem here where value is not being accessed properly
  7.   //it should be '${myGift["value"]}'instead of '${'myGift[value]'}';
  8.   var amount = '${myGift["value"]}';
  9.   print(amount);
  10.   print(amount.runtimeType);
  11. //so now that we got it as a proper string, time to convert
  12.   var num = int.parse(amount);
  13.   print(num.runtimeType);
  14. //some operations
  15.   var result = 1 + num;
  16.   print(result);
  17.   print("however what happens if you put a float instead?");
  18.   var myGift2 = {"value": 1.25};
  19.   print(myGift2);
  20.   var amount2 = '${myGift2["value"]}';
  21.   print(amount2);
  22.   print(amount2.runtimeType);
  23.   var num2 = int.parse(amount);
  24.   print(num2);
  25.   print("as you can see it gets truncated");
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement