我正在尝试转换一个整型变量。
var int counter = 0;
转换成字符串变量
var String $counter = "0";
我进行了搜索,但只找到了类似于
var myInt = int.parse('12345');
无法使用
var myInt = int.parse(counter);
使用 toString
和/或 toRadixString
int intValue = 1;
String stringValue = intValue.toString();
String hexValue = intValue.toRadixString(16);
或者,就像评论中所说的那样
String anotherValue = 'the value is $intValue';
String s = "45";
int i = int.parse(s);
int j = 45;
String t = "$j";
// 如果后者看起来很奇怪,请查阅https://dart.dev上的字符串插值。
你可以在int类中使用.toString()函数。
int age = 23;
String tempAge = age.toString();
那么您可以简单地将整数转换为字符串。
String stringValue = '$intValue';
- greyaurora