• ### truncate all elements in a list?

Hello forum!

Need a pd wizard to help me. I need to be able to truncate all the floats in a list to a certain decimal point. Or, if we want to be really clever, round these numbers to the nearest (truncated) decimal value.

For example, I need a way to turn [0.835587 0.16678 0.38896, 54.3221 -4.567776( into [0.84 0.17 0.39 54.32 -4.57(. I'm sure I could spend hours thinking about this but I was wondering if anyone knows of an easy object that does this.

• Posts 7 | Views 2369
• I don't know of any object that would do that (and that would be handy!), but you can try something like this:

[int] and [wrap] will first separate the number into integer part and floating point part, respectively. Then a bit of math trickery can do the job

Hope this helps, cheers!
Gilberto

• list-round from list-abs, with ".01" sent to the right inlet

• @gsagostinho hey really quick question: what's the function of the [mod 10] in your chain? Aren't those numbers already going to be between 0-9? Sorry I don't have access to a computer right now I just wanted to ask before I forgot.

• @rjp9 Not really, the numbers that interest me are running between 0-9 but there might be other things to discard. E.g.: look at the rightmost part of the code, after the 0.456 has been fed to the [t f f]. So it's multiplied by 100, and now we have 45.6, then the [int] will make it a 45, and a [mod 10] will extract the last digit, in this case 5. Then dividing it by 100 makes it once again a 0.05.

@seb-harmonik-ar I didn't know [list-round], thanks for the tip!

• Another really useful tool is [list-map], which lets you perform customized operations on a list.

Posts 7 | Views 2369
Internal error.

Oops! Looks like something went wrong!