kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Mar 19, 2019 2:14:10 GMT
Is there an obvious method to truncate a float? or reduce the precision of it for display?
i want these
1.851852 1.323412 2.452553 40.34221
to become these...
1.851 1.323 2.452 40.343
|
|
|
Post by xPsycHoWasPx on Mar 19, 2019 16:53:58 GMT
Easy
floor(1.851852 * 1000) /1000
1.851852 * 1000 = 1851.852
Floor(1851.852) = 1851
1851/1000 = 1.851
But round() can be used 2. If you want it to be 1.852 that is nearest whole.
|
|
kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Mar 25, 2019 15:35:24 GMT
Damn. This just brought back a whole number of programming concepts that I had forgotten. Thanks rad dude!
|
|
kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Apr 1, 2019 16:13:41 GMT
Ok... so i tried this but when I render it to a text field it just stacks on the extra 0z.
|
|
|
Post by xPsycHoWasPx on Apr 4, 2019 0:07:21 GMT
Yea I noticed that floats in text boxes/canvas will create extra 000.
Haven't tested this but, since its text, the number can be converted to a text string instead. so a method would be like:
input = 1.851852 val_1 = floor(input) val_2 = round((input - val_1)*1000)
val_1= 1 val_2= 852
new_float = '' + val_1 + '.' + val_2
setattribute(text_object,'content',new_float) new_float = "1.852" but displayed: 1.852
so depending on how many values u want after . then change *1000 to *100 if u want just 1.85
but the new_float can't be used for any math only text display since its now converted to a text_string by doing the + '' . but this is how i created the displaying of arrays in the log_message module.
|
|
kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Apr 7, 2019 2:01:46 GMT
100% works this way. you are the man!
I realize now it seems easier to just put this in a monitor object and set the precision using that. I wish we knew more about these under the hood. I figured text objects use less memory.
|
|
kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Apr 7, 2019 2:54:08 GMT
lol... ok i always speak so soon... i'll see if i can come up with a solution for this but if you get a value like 0.005 it flattens the number to 0.5. not holding the number of characters. Just gonna go with using a monitor in the meantime.
|
|
|
Post by xPsycHoWasPx on Apr 7, 2019 8:12:29 GMT
Yea use Monitor if you only gonna display a single float value. Text object trick is for when mixing text and floats.
0.0x values in text will require another “for loop” trick. I can show when i got time. Busy atm with my ableton live control project
|
|
kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Apr 7, 2019 16:28:56 GMT
Yea use Monitor if you only gonna display a single float value. Text object trick is for when mixing text and floats. 0.0x values in text will require another “for loop” trick. I can show when i got time. Busy atm with my ableton live control project don't sweat it man. i understand there is a way out with more code. monitor will save me
|
|
kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Apr 7, 2019 16:29:15 GMT
|
|