# How to convert decimals to integers and joint them to a string for exporting

There's a list such as {0.1,2,0.15,5}. I want to know how to convert the decimal to integer( but begin with zero 0), and don't touch the integer. In the second step, joint the data to a string "a01b2c015d5". Note that the data in the printed string are separated with a,b,c and d, because I have tons of data to mark with a, b, c and d. Finally, export a01b2c015d5={0.1,2,0.15,5} to the file exportData.txt. How to do it? Thank you!

• This will generate the string you want: StringReplace[ToString@Thread[{{a, b, c, d}, {0.1, 2, 0.15, 5}}], {"," -> "","." -> "", " " -> "", "{" -> "", "}" -> ""}]. But I assume you'd want to do this repeatedly, for your entire dataset. To tell you how to do that, we'd need to see a minimal working example of your dataset, so we can see the structure. May 10, 2021 at 4:42
• @theorist, Thanks, this is a great idea. May 10, 2021 at 6:12

Try

StringJoin[StringTake[StringReplace[ToString[Flatten[Transpose[
{{a,b,c,d},{0.1,2,0.15,5}}]]],{","->"","."->""," "->""}],{2,-2}],
"=",ToString[{0.1,2,0.15,5}]]


Start from the innermost nested function, strip that out, run it, see what it does, then look it up in the documentation and see if you can understand why that does what it does and how it gets the input slightly closer to the output that you want, then repeat with each next outer layer.

Then you can export that resulting string to your file.

If you carefully do that then you should greatly improve your skills to be better able to do your next problem.

• Thanks. It's really a short and effective way to the point. May 10, 2021 at 6:06
• Thank you @Bill, I want to know why the code from exported file can not be used to calculate when the exported file format is .m, for example the file name is exported.m, the form of exported data is "a01b2c015d5={0.1, 2, 0.15, 5}", which includes a pair of double quotation marks. How to export the file for using the exported codes directly? Thanks May 10, 2021 at 8:40
• Thank you very much. May 10, 2021 at 8:51
• Read en.wikipedia.org/wiki/XY_problem Maybe you could edit your original question to say what you REALLY want to accomplish, instead of asking how to do one step that you think will get you where you want to go. Perhaps with the real problem clearly described then someone might be able to suggest a simpler way to get where you need to go.
– Bill
May 10, 2021 at 9:05