float to fixed length decimal

Hints, tips and discussion about graphics and user interface elements

Moderators: electrogear, exonerate

float to fixed length decimal

Postby oddson on Mon Aug 29, 2005 7:04 am

Image

I'm looking for something that will get me this result.

I've started to 'write' it with SM parts but it's getting much more complex than I think it should be.

Anybody got a bright idea how to do this within SM?

Any chance this is coming as a primative?

p.s. - not merely looking to 'round' but to allow '3.013' to show '3.0' if decimal is set to 1 (and not show '3')
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

fixed decimal strings

Postby oddson on Mon Aug 29, 2005 7:23 am

OK - so I found this in another thread. One day I'll learn how to search this forum effectively before I post. 3:)

Jorge asked the use of it would be.

It's for display purposes - that's why in my sleep deprived condition I posted what looks like a math question in the graphics from.

I'd like to be able to display the current decimal value of a parameter without it jumping around as it drops zeros from the back end of the string or without showing 7 decimal places when in most cases 2 or 3 is plenty.
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

Postby malc on Mon Aug 29, 2005 8:53 am

We can probably make a very low-level component for string formatting based on the standard c/c++ format specifications. Very easy and has been on our todo list for some time.

You'd need to use the format specifications as outlined here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt_format_specification_fields_.2d_.printf_and_wprintf_functions.asp

To get 3 decimal places all you'd need to do is use ".3f" as the format specification meaning (the f means floating point).
User avatar
malc
smychopath
 
Posts: 3111
Joined: Tue Sep 07, 2004 11:17 pm
Location: UK

Postby stefan on Mon Aug 29, 2005 9:24 am

Unfortunately there's no way to _increase_ the number of decimals currently shown, but we can atleast set them to any number below that by doing some integer "tricks".

Image
Stefan
User avatar
stefan
smunatic
 
Posts: 2384
Joined: Wed Dec 15, 2004 9:24 pm
Location: Gothenburg, Sweden

Postby oddson on Mon Aug 29, 2005 9:37 pm

Problem with 'tricks' is zero's are still dropped from the display from floats - no matter what you do (or at least no matter what I did).

3.4 to 3 decimals is still 3.4 not 3.400

I played around last night with string manipulations until it got so complex I just gave up.
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

Postby malc on Mon Aug 29, 2005 9:47 pm

Don't waste any more time on workarounds oddson - new component in the next release :-)
User avatar
malc
smychopath
 
Posts: 3111
Joined: Tue Sep 07, 2004 11:17 pm
Location: UK

Postby oddson on Mon Aug 29, 2005 10:51 pm

When most developers say "it's in the next release" you get ready for a long wait - you guys seem to release about twice a week. :D
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

Postby oddson on Wed Aug 31, 2005 3:27 am

More than I hoped for and faster too. What was that 2 days? :o

Image

I love that I can have string content after the format!

I see there's some bugs but I'm still impressed. :D


Some documentation would be great (as always) but I'll use printf() documentation from the link above for now.

Thanx! :) :D ;)
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

Postby infuzion on Tue Mar 28, 2006 6:03 am

You know, I'm still not sure what & what isn't included from Microsoft's docs in Format... can someone make a handy summery chart please?
cheers
Need help? First search the forum & WiKi, then post in the help forum with a clear topic, request, & OSM. Then please WiKi the correct solution. If you want my personal assistance, I charge by the hour or for an exchange of services.
infuzion
smstar
smstar
 
Posts: 6163
Joined: Wed May 04, 2005 8:02 pm
Location: Earth, USA, CO, Denver

Postby doug4350 on Fri Mar 31, 2006 4:04 am

Try this... I'm assuming they're doing an sprintf underneath.

http://www.cplusplus.com/ref/cstdio/sprintf.html

Aloha,
Doug
doug4350
essemilian
 
Posts: 312
Joined: Sat Dec 03, 2005 6:15 am
Location: Hawaii

Postby infuzion on Fri Mar 31, 2006 5:14 am

doug4350 wrote:Try this... I'm assuming they're doing an sprintf underneath.
http://www.cplusplus.com/ref/cstdio/sprintf.html
ahhh, much easier to read; thanks!
Need help? First search the forum & WiKi, then post in the help forum with a clear topic, request, & OSM. Then please WiKi the correct solution. If you want my personal assistance, I charge by the hour or for an exchange of services.
infuzion
smstar
smstar
 
Posts: 6163
Joined: Wed May 04, 2005 8:02 pm
Location: Earth, USA, CO, Denver

Postby oddson on Tue Mar 04, 2008 4:14 am

Given many reports of instability in the Format String primitive I have wrapped it in a module to produce the original intended result of a fixed decimal string.

formatFloat.osm
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

Postby infuzion on Tue Mar 04, 2008 5:40 am

oddson wrote:formatFloat.osm
That's handy; thanks.

Could someone make an all-options-inclusive version that any (float atleast) formating that can be done with the Format String be selected via GUI please? Like how the Label primitive has the Font & Format preferences that gives the user all options visually via the GUI.

What I was really looking for is an output like this:
+1
+.75
+.5
0
-.25
-1
But I'm sure in the future I'd want some other funky formatting.

I personally prefer the module to have an output of a String value to be connected to the Format String on the outside, feeding the 2nd input. That way, one can feed a String, then remove the module when you're happy with the formatting.
cheers!
Need help? First search the forum & WiKi, then post in the help forum with a clear topic, request, & OSM. Then please WiKi the correct solution. If you want my personal assistance, I charge by the hour or for an exchange of services.
infuzion
smstar
smstar
 
Posts: 6163
Joined: Wed May 04, 2005 8:02 pm
Location: Earth, USA, CO, Denver

Postby Acrobat on Tue Mar 04, 2008 7:03 am

infuzion wrote:What I was really looking for is an output like this:
+1
+.75
+.5
0
-.25
-1


You mean every quarter of unit? I did it, I'll search and post...
User avatar
Acrobat
smaniac
 
Posts: 1660
Joined: Mon Jun 04, 2007 10:50 pm
Location: Roma, Italia

Postby oddson on Tue Mar 04, 2008 7:52 am

formatString.osm

Does as much of the formatting as you'd likely want with a float and the format string generator is purged when compiled to VST.
oddson
wiki guru
 
Posts: 3883
Joined: Sun Jul 03, 2005 6:44 pm

Next

Return to Graphics

Who is online

Users browsing this forum: No registered users and 2 guests