Anyone a suggestion on how to convert a string to a number in TypeScript?
(有人建议如何将字符串转换为TypeScript中的数字?)
var aNumber : number = "1"; // --> Error
// Could this be done?
var defaultValue = 0;
var aNumber : number = "1".toInt32(defaultValue);
// Or ..
var defaultValue = 0;
var aNumber : number = StringToInt("1", defaultValue);
Update: I did some extra puzzling, the best sofar I've come up with: var aNumber : number = ( "1") * 1;
(更新:我做了一些额外的困惑,我想出的最好的音乐:var aNumber:number =(“1”)* 1;)
checking if a string is numeric is answered here: In Typescript, How to check if a string is Numeric .
(检查字符串是否为数字在此处回答: 在Typescript中,如何检查字符串是否为数字 。)
ask by Paul0515 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…