Jump to content

Write float arrays to a text file: Difference between revisions

Added Kotlin
m (→‎{{header|Sidef}}: updated code)
(Added Kotlin)
Line 725:
y = round([1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791],yprecision)
writedlm("filename", [x y], '\t')</lang>
 
=={{header|Kotlin}}==
<lang scala>// version 1.1.1
 
import java.io.File
 
fun main(args: Array<String>) {
val x = doubleArrayOf(1.0, 2.0, 3.0, 1e11)
val y = doubleArrayOf(1.0, 1.4142135623730951, 1.7320508075688772, 316227.76601683791)
val xp = 3
val yp = 5
val f = "%.${xp}g\t%.${yp}g\n"
val writer = File("output.txt").writer()
writer.use {
for (i in 0 until x.size) {
val s = f.format(x[i], y[i])
writer.write(s)
}
}
}</lang>
 
Contents of 'output.txt':
<pre>
1.00 1.0000
2.00 1.4142
3.00 1.7321
1.00e+11 3.1623e+05
</pre>
 
=={{header|Lingo}}==
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.