Reducing floats to cents to display

For general discussion related FlowStone
Post Reply
User avatar
CoreStylerz
Posts: 327
Joined: Sun Jan 22, 2012 2:19 am
Location: italy
Contact:

Reducing floats to cents to display

Post 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?
Need my support for app development, website or custom scripts?
PM me if you are interested.
Experienced Java, J2EE, PHP, Javascript, Angular, Cloud Solutions developer.
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Reducing floats to cents to display

Post 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"
User avatar
CoreStylerz
Posts: 327
Joined: Sun Jan 22, 2012 2:19 am
Location: italy
Contact:

Re: Reducing floats to cents to display

Post by CoreStylerz »

Ty, i've downloaded back synthmaker. ;)
Need my support for app development, website or custom scripts?
PM me if you are interested.
Experienced Java, J2EE, PHP, Javascript, Angular, Cloud Solutions developer.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: Reducing floats to cents to display

Post 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.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
User avatar
CoreStylerz
Posts: 327
Joined: Sun Jan 22, 2012 2:19 am
Location: italy
Contact:

Re: Reducing floats to cents to display

Post by CoreStylerz »

With ruby should be easy, i've use the old module it works good. ;)
Need my support for app development, website or custom scripts?
PM me if you are interested.
Experienced Java, J2EE, PHP, Javascript, Angular, Cloud Solutions developer.
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: Reducing floats to cents to display

Post by Nubeat7 »

its about the same in ruby..

Code: Select all

val_string = "%0.2f"%@value.to_s
User avatar
CoreStylerz
Posts: 327
Joined: Sun Jan 22, 2012 2:19 am
Location: italy
Contact:

Re: Reducing floats to cents to display

Post 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
Need my support for app development, website or custom scripts?
PM me if you are interested.
Experienced Java, J2EE, PHP, Javascript, Angular, Cloud Solutions developer.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: Reducing floats to cents to display

Post 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.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
User avatar
CoreStylerz
Posts: 327
Joined: Sun Jan 22, 2012 2:19 am
Location: italy
Contact:

Re: Reducing floats to cents to display

Post 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
Need my support for app development, website or custom scripts?
PM me if you are interested.
Experienced Java, J2EE, PHP, Javascript, Angular, Cloud Solutions developer.
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: Reducing floats to cents to display

Post 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
Post Reply