I have a number: 466.62 as a double and can't change it to a string, how can I get rid of the decimal point and print 46662? I've managed to get 46662.0 by multiplying the value by 100, but I don't want to print the decimal point. Thanks
When you multiply 466.62 by 100, your end result will remain a double as well. This is why you are seeing 46662.0. So you need to convert it to Int value, so instead you should do it like this:
double vDouble = 466.62 *100
String vString = vDouble.toInt().toString();
This will give you 4662.
For a more generic case, use the String split method;
String str = '466.62';
//split string
var arr = str.split('.');
print(arr[0]); //will print 466
print(are[1]); //will print 62
After you have managed to get this 46662.0,
Use this :
46662.0.toStringAsFixed(0);
print(46662.0.toStringAsFixed(0));- This gives 46662
print(46662.0.toStringAsFixed(0).runtimeType);- This gives as String.
Reference : https://api.dart.dev/stable/2.8.4/dart-core/num/toStringAsFixed.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With