开发者

integer to [String]

开发者 https://www.devze.com 2023-01-21 06:36 出处:网络
with this code digs 0 =开发者_C百科 [] digs x = x `mod` 1000 : digs (x `div` 1000) for example: 24889375

with this code

digs 0 =开发者_C百科 []

digs x = x `mod` 1000 : digs (x `div` 1000)

for example: 24889375

we take the result [375,889,24]

how can i make this one ["375","889","024"]


Prelude> import Text.Printf
Prelude Text.Printf> map (printf "%03d" :: Int -> String) [375,889,24]
["375","889","024"]


The most idiomatic way to do this is to use the functions map and show.

Prelude> map show [375,889,24]
["375","889","024"]

show can be used to convert most values to a string. map applies that function to every element of a list map.

0

精彩评论

暂无评论...
验证码 换一张
取 消