SynthMaker

float to fixed length decimal

Archive · 2005 18 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

oddson ·

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 ·

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

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.

malc ·

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).

stefan ·

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".

oddson ·

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.

malc ·

Don't waste any more time on workarounds oddson - new component in the next release 🙂

oddson ·

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. 😀

oddson ·

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

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

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

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

Thanx! 🙂 😀 😉

infuzion ·

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

doug4350 ·

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

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

Aloha, Doug

infuzion ·

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!

oddson ·

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

infuzion ·

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!

Acrobat ·

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...

oddson ·

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.

BasherT ·

This is really useful Oddson.

I have noticed however that if you have the + checked and you feed the module a value of zero the output is "+0". Not sure what to do about that as I can't get my head round this formatting stuff at all. Any ideas?

BasherT ·

After hours trying to get to grips with the intricacies of the format codes, I came up with a solution to this by using a simply switch to change the format to one that does not show the sign when the value equals zero!

infuzion ·

BasherT wrote: I have noticed however that if you have the + checked and you feed the module a value of zero the output is "+0". Not sure what to do about that as I can't get my head round this formatting stuff at all. Any ideas?

There is a difference between +0 & -0. But for what I used it for, I didn't like it. So I think I connected the output to either a Float or String primitive to get rid of it... I forget, maybe both?

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.