Page 1 of 1

Reducing floats to cents to display

Posted: Thu Jun 12, 2014 12:58 am
by CoreStylerz
I want to reduce the output display of knob values.
I tried with string extract but to works also with negative values i have to use logic.
Is possibile to do such things with string format primitive.
Since i want values like 0,00 and -0,00

Any help?

Re: Reducing floats to cents to display

Posted: Thu Jun 12, 2014 5:25 am
by KG_is_back
This is implemented in float label in synthmaker. If you have it copy it from there...

the specification string looks something like this: number for example 5.468464
%.2f - rounds number to two decimal places - example: "5.47"
%8.2f - displays 8 chars (padded with spaces) with two decimal places - example: " 5.47" (notice the 4 spaces before the 5... decimal dot is consider a char too)
%08.2f - displays 8 chars (padded with zeroes) with two decimal places - example: "00005.47"

Re: Reducing floats to cents to display

Posted: Thu Jun 12, 2014 10:56 am
by CoreStylerz
Ty, i've downloaded back synthmaker. ;)

Re: Reducing floats to cents to display

Posted: Thu Jun 12, 2014 1:40 pm
by tester
...and you use format string primitive for that (or ruby), connected to label via string connector. Trog wrote here sometime ago how to format values in ruby boxes (format defs can be provided from outside). Search the forum here or via google (since searching isn't/wasn't working correctly) - keywords like format string array.

Re: Reducing floats to cents to display

Posted: Thu Jun 12, 2014 2:53 pm
by CoreStylerz
With ruby should be easy, i've use the old module it works good. ;)

Re: Reducing floats to cents to display

Posted: Thu Jun 12, 2014 7:34 pm
by Nubeat7
its about the same in ruby..

Code: Select all

val_string = "%0.2f"%@value.to_s

Re: Reducing floats to cents to display

Posted: Fri Jun 13, 2014 12:24 am
by CoreStylerz
Ty nubeat,
The primite works but seems to be buggy and unstable. It's stable but if i put some wrong tags it crashes flowstone... :o

Re: Reducing floats to cents to display

Posted: Fri Jun 13, 2014 12:59 am
by tester
1) Put right tags into string primitive.
2) Connect the string primitive to format prim.
3) Make a module and add to the toolbox.

Usually you will use always the same stuff, maybe different numbers.

Format prim was always crashing (also synthmaker) when connected to bad tags. But if using correct tags - it works fine.

Re: Reducing floats to cents to display

Posted: Fri Jun 13, 2014 1:55 am
by CoreStylerz
tester wrote:1) Put right tags into string primitive.
2) Connect the string primitive to format prim.
3) Make a module and add to the toolbox.

Usually you will use always the same stuff, maybe different numbers.

Format prim was always crashing (also synthmaker) when connected to bad tags. But if using correct tags - it works fine.

thanks

Re: Reducing floats to cents to display

Posted: Fri Jun 13, 2014 6:37 am
by billv
Would "round" help here...

Code: Select all

1.234567.round(2)  #=> 1.23
1.234567.round(3)  #=> 1.235
1.234567.round(4)  #=> 1.2346
1.234567.round(5)  #=> 1.23457

http://ruby-doc.org/core-2.1.2/Float.html