英文:
How to convert Int of Array values to Double using Swift
问题
在我的场景中,我试图在整数值数组之前添加零点。例如,我的整数值数组如下:50
,但在传递给AMProgress之前,我需要添加零,使其变为0.50
。如果出现0.100
,需要更改为1
。如何实现这一目标?
我的代码如下
let data: [Int] = [1, 2, 4, 5, 6, 7, 8, 4, 23, 54, 100]
所需输出:0.1、0.2、0.3、等等...
英文:
In myscenario, I am trying to add zero with point before array of Integer value. For example my array of integer values like 50
but before passing to AMProgress I need to add like 0.50
. If supposed 0.100
came need to change like 1
. How to achieve this?
My Code Below
let data : [Int] = [1,2,4,5,6,7,8,4,23,54,100]
Required output: 0.1, 0.2, 0.3, etc,...
答案1
得分: 1
Output:
[0.01, 0.02, 0.04, 0.05, 0.06, 0.07, 0.08, 0.04, 0.23, 0.54, 1.0]
英文:
let data : [Int] = [1,2,4,5,6,7,8,4,23,54,100]
let convertedData = data.map { Double($0)/100}
Output:
[0.01, 0.02, 0.04, 0.05, 0.06, 0.07, 0.08, 0.04, 0.23, 0.54, 1.0]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论