bigdecimal - Array in scala produced by x to y by z resulting in long decimals -


i trying generate numeric range of double val arrayofdoubles = (0.0 1.0 0.1).toarray, resultant not expected be. result array(0.0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999). why this. use code expect be:

val roundedarray = (x <- arrayofdoubles) yield  bigdecimal(x).setscale(1, bigdecimal.roundingmode.half_up).todouble 

which results in array[double] = array(0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0)but looks cumbersome , expensive bigdecimal converts double string , parse it.

is there way numericrange rounded 1 decimal place?

thanks.

0 10 map (_ / 10.0) 

should trick


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -