Author Topic: Format INTs or DECs with commas  (Read 7488 times)

omega9380

  • Guest
Format INTs or DECs with commas
« on: January 15, 2017, 12:43:48 PM »
Not sure if there is a way to do this now, but I'll put the suggestion out there.

I use VA with EDDI to write a running computer log of my ED sessions using the "Write text to file" action.  My feature request is a function to format INT and DEC variables over 1000 with commas.  For example, the population of Achenar in Elite is 12,999,999,523.  When I write the value of the variable to my file, it outputs as "12999999523".  I would like a function to display that number with commas.

Example:
Instead of {DEC:System population}, which outputs "12999999523", we would use {DECCOMMA:System population} to output "12,999,999,523".

This is for a niche set of users, most people need the voice responses (Hence, VOICE attack) but it would be a nice little addition for those of us that use "Write text to file" a lot.  Thanks!!!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Format INTs or DECs with commas
« Reply #1 on: January 15, 2017, 01:35:38 PM »
Quote
{INTFORMAT:variableName} - This returns the same value as {INT}, but the value is formatted with commas (for TTS).

This token is not available for Decimals, but it's one half of your request fulfilled in advance :P


Though, why it says "for TTS" I'm not sure, as TTS has predefined rules for pronouncing numbers, and in practice I don't hear any difference either.

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: Format INTs or DECs with commas
« Reply #2 on: January 20, 2017, 02:19:08 AM »
I fully support this omega9380!!

Just having a same problem with shis TTS -thingy. Currently trying this variable {SMALLFORMAT:nameofthesmallint} to be said/spoken, but there is absolutely no difference to {SMALL:nameofthesmallint} how it's been said/interpreted by the speech engine

EDIT: Just tested to write it using the {SMALLFORMAT:nameofthesmallint} variable into the VA log, and the result is quite clear,- as it types it/ it is written in number format,- not commas format. I would call this a bug  :P

Anyways, I found a website related to this for web designer coding stuff (i simply don't know how to figure out a workaround until we get a new variable fix for this...) Check examples plz:

3.5 Cardinal number
3.6 Ordinal number

https://www.w3.org/TR/ssml-sayas/#S3.5
« Last Edit: January 20, 2017, 02:40:25 AM by FireSammy »

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Format INTs or DECs with commas
« Reply #3 on: January 20, 2017, 03:29:27 AM »
If you need it right now, you should be able to do it using inline C#:
Code: [Select]
Set decimal [InputDecimal] value to 143214324324320,00000
Inline C# Function:
Write '[Purple] {TXT:OutputDecimal}' to log

Where the inline function contains
Code: [Select]
using System;

public class VAInline
{
public void main()
{
            VA.SetText("OutputDecimal", String.Format("{0:n0}", VA.GetDecimal("InputDecimal")));
      }
}

Problem is I can't test it, because I don't use the same formatting you do, so try it and let me know what the output looks like(note that it won't return any decimal places).

EDIT: Works if you do it right and don't try to cast the decimal to string before converting it to string, heh.
« Last Edit: January 21, 2017, 03:08:03 AM by Pfeil »

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: Format INTs or DECs with commas
« Reply #4 on: January 20, 2017, 08:47:01 AM »
Thank you Pfeil, i'll get back on that asap, but oki eerh... bare with me here please for a sec (sweat pouring from mi forehead again)... :P

referring to the forum "Text Tokens in VA" -post
http://voiceattack.com/smf/index.php?topic=31.0

----------------

{CONDFORMAT:conditionName} - This returns the same value as {COND}, but the value
is formatted with commas (for TTS). This used to be the default behavior of {COND}, but,
since the introduction of the {EXP} token, this token had to be created.

{SMALLFORMAT:variableName} - This returns the same value as {SMALL}, but the value
is formatted with commas (for TTS). This used to be the default behavior of {SMALL}, but,
since the introduction of the {EXP} token, this token had to be created.

{INTFORMAT:variableName} - This returns the same value as {INT}, but the value is
formatted with commas (for TTS). This used to be the default behavior of {INT}, but,
since the introduction of the {EXP} token, this token had to be created.

----------------

First question:
Where is the "{DECFORMAT:variableName} - This returns the same value as {DEC}, but the value is
formatted with commas (for TTS). This used to be the default behavior of {DEC}, but,
since the introduction of the {EXP} token, this token had to be created"???

First suggestion:
I would see this useful, more clear, and even more useful than the existing ones above. If i understood the omega9380's post correctly, this is exactly what he is asking, and i support that fully. Even if this variable is/can be interpreted being the same as {INTFORMAT:variableName}, (which i simply cannot understand being the same just by looking at it) it should be added because of this reason alone, please make this {DECFORMAT:variableName} variable, thank you :)

----------------
Second question(s):
Sorry for my ignorance, but English is not my mother language (EU/Finland) and these math codes (commas and punctuation's) are really not my area of expertise yet (newbie)... Just making sure I've understood these correctly. Are the existing variables above (if worked as meant to work -not a bug) so-posed to convert the given value from the default form, for example:

Number 1 converted to 1. aka 1st = Then TTS speech engine should understand this as an ordinal number 'First'? Right? :o :P (I guess not... Been typing this all day trying to make sense out of this and i think i see my mistake here now)

Or, it's just adding a comma(s) there without any expected change to the TTS speech engines pronounciacion/way of saying that value, but only when given longer/bigger numbers, especially with decimal digits, it would be converting the numbers for example 1,234,567 as according to this link:

http://englishplus.com/grammar/00000087.htm

If/when this is indeed the case, i think there is definitely a need for additional types of -spoken "FORMAT" variables if/when adding the comma(s) (described above) is all that this current variable does. I'll make a separate suggestions post for that issue later...

Anyways, therefore, second related suggestion following:

For example the {CONDFORMAT:conditionName} variable description - This returns the same value as {COND}, but the value is formatted with commas (", for example: In numbers of more than three digits, converts/adds commas after every third digit from right to left 1,234,567 for both, text output and spoken speech (TTS). Note: Not to be confused with different TTS spoken ordinal number formats"). This used to be the default behavior of {COND}, but, since the introduction of the {EXP} token, this token had to be created.

("This") should be added to the explanation section of the variables using "FORMAT" -preventing any unnecessary misunderstandings in the future, please, thank you. Just mentioning the (for TTS) got me completely off track here, in other words, misleading, thinking it would convert numbers into TTS spoken ordinal number format with commas added :P

Please correct me if i got this completely wrong guys :o
« Last Edit: January 20, 2017, 09:59:04 AM by FireSammy »

omega9380

  • Guest
Re: Format INTs or DECs with commas
« Reply #5 on: January 20, 2017, 06:11:47 PM »
Looks like you don't need "ToString" after calling the decimal.  The code would be:

Code: [Select]
VA.SetText("OutputDecimal", String.Format("{0:N0}", VA.GetDecimal("InputDecimal")));
If you run ToString on GetDecimal, the formatting doesn't work.  Without it, it runs perfect!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Format INTs or DECs with commas
« Reply #6 on: January 21, 2017, 03:32:54 AM »
Where is the "{DECFORMAT:variableName}
It doesn't exist yet, that's why I said
it's one half of your request fulfilled in advance
Because you can do it with the Integer datatype already, but not the Decimal datatype.

Or, it's just adding a comma(s) there without any expected change to the TTS speech engines pronounciacion/way of saying that value
At least in the default "Microsoft Anna - English (United States)" TTS voice, it doesn't make any difference as far as I can tell.

Internally, the voice(which is just another piece of software) has rules to pronounce "123456789" as one hundred twenty three million ,four hundred fifty six thousand ,seven hundred eighty nine" instead of "One Two Three Four Five Six Seven Eight Nine".

If your TTS voice doesn't do this, I'd call that an omission on the manufacturers part.

mentioning the (for TTS) got me completely off track here, in other words, misleading, thinking it would convert numbers into TTS spoken ordinal number format with commas added :P
I'm not sure if adding commas makes a difference in any TTS voice, but it might.

However, "Microsoft Anna - English (United States)" doesn't need commas to pronounce ordinal numbers, just the suffix "th". The rules are clever enough to pronounce "1th" as "First", "3th" as "Third", and so on.

It'll pronounce "123456789th" as one "hundred twenty three million ,four hundred fifty six thousand ,seven hundred eighty nineth".

Note that you may need to listen carefully to hear the "th", it's pronounced fairly weak and short with some numbers.


If you run ToString on GetDecimal, the formatting doesn't work.  Without it, it runs perfect!
Ah, indeed. "Converts the value of objects to strings", I should have known the cast was unnecessary. Glad you got it working, anyways.

FireSammy

  • Newbie
  • *
  • Posts: 43
Re: Format INTs or DECs with commas
« Reply #7 on: January 22, 2017, 05:27:35 AM »
It doesn't exist yet, that's why I said
Yah m8, and that's why i think it would be good to have one, cheers ;)

At least in the default "Microsoft Anna - English (United States)" TTS voice, it doesn't make any difference as far as I can tell.

Internally, the voice(which is just another piece of software) has rules to pronounce "123456789" as one hundred twenty three million ,four hundred fifty six thousand ,seven hundred eighty nine" instead of "One Two Three Four Five Six Seven Eight Nine".

If your TTS voice doesn't do this, I'd call that an omission on the manufacturers part.
Thank you for this info. Yah, i'm using the default "Microsoft Anna - English (United States)" TTS voice, with WIN 7 64bit Ultimate, and planning to upgrade this machine to WIN 10 asap.

, just the suffix "th". The rules are clever enough to pronounce "1th" as "First", "3th" as "Third", and so on.

It'll pronounce "123456789th" as one "hundred twenty three million ,four hundred fifty six thousand ,seven hundred eighty nineth".

Note that you may need to listen carefully to hear the "th", it's pronounced fairly weak and short with some numbers.
Ohh this is really good advice/info!!!!! I have not yet done any "suffix/prefix" stuff, but i sure will try to get this thing going now!! Huge thanks! :)

If you need it right now, you should be able to do it using inline C#:
Code: [Select]
Set decimal [InputDecimal] value to 143214324324320,00000
Inline C# Function:
Write '[Purple] {TXT:OutputDecimal}' to log

Where the inline function contains
Code: [Select]
using System;

public class VAInline
{
public void main()
{
            VA.SetText("OutputDecimal", String.Format("{0:n0}", VA.GetDecimal("InputDecimal")));
      }
}

Problem is I can't test it, because I don't use the same formatting you do, so try it and let me know what the output looks like(note that it won't return any decimal places).

EDIT: Works if you do it right and don't try to cast the decimal to string before converting it to string, heh.
Errh this stuff is still way over my head... Thank you anyways, and you guys got this thing sorted i see :)

I repeat: I humbly thank you very much for detailed replys!

Bumble B

  • Jr. Member
  • **
  • Posts: 64
    • Bumble B Gaming
Re: Format INTs or DECs with commas
« Reply #8 on: March 25, 2017, 09:06:39 AM »
Anymore info on this as I'm currently looking into doing something with my DEC variables  to show up as 1,000 instead of 1000 etc for my twitch stream overlays
--
CMDR Bumble B รถ7
ASUS P6TD Deluxe, Intel i7 960 @ 3.2GHz, 12Gb G.Skill, Windows 7 SP1 (64bit), ASUS Geforce GTX 970 Strix (4Gb), ThrustMaster T-Flight HOTAS X, Cosair Void RGB USB Gaming Headset, TrackIR, EDDI, Voice Attack, ED Engineer