How to deal with decimal number in scala -


i have file this:

1    4.146846 2    3.201141 3    3.016736 4    2.729412 

i want use todouble but, it's not working expected :

val rows = textfile.map { line =>        val fields = line.split("[^\\d]+")       ((fields(0),fields(1).todouble))      }  val num = rows.sortby(- _._2).map{case (user , num) => num}.collect.mkstring("::")  println(num) 

the result print out 4.0::3.0::3.0::2.0.
expect 4.146846::3.201141::3.016736::2.729412

how do this?

your regular expression stopping @ decimal point in 4.146846.

try line.split("[^\\d.]+")


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -