Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //run this in https://dartpad.dev
- void main() {
- //I'm assuming you saved the data in this form
- var myGift = {"value": 1};
- print(myGift);
- //so I'm also seeing a problem here where value is not being accessed properly
- //it should be '${myGift["value"]}'instead of '${'myGift[value]'}';
- var amount = '${myGift["value"]}';
- print(amount);
- print(amount.runtimeType);
- //so now that we got it as a proper string, time to convert
- var num = int.parse(amount);
- print(num.runtimeType);
- //some operations
- var result = 1 + num;
- print(result);
- print("however what happens if you put a float instead?");
- var myGift2 = {"value": 1.25};
- print(myGift2);
- var amount2 = '${myGift2["value"]}';
- print(amount2);
- print(amount2.runtimeType);
- var num2 = int.parse(amount);
- print(num2);
- print("as you can see it gets truncated");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement