| 10-18-2004, 03:15 AM | #1 |
You might not understand the topic, but look at this trigger: Game - Display to (Triggering player), at offset (0.00, 0.00) the text: (This warrior has an experience level of: + (String((Hero experience of (Target unit of ability being cast))))) The max EXP in my map is well over 1,000,000,000. When you cast this ability and the target has an exp of over 1,000,000,000, it appears as 1198554115. What I want to know is if it is possible to Either display the number with commas or spaces in between each three integers. Examples: 1,198,554,115 1 198 544 115 |
| 10-18-2004, 03:35 AM | #2 |
You could set the set the number too a variable, and format it prior to displaying it. For example: Set string = (String((Hero experience of (Triggering unit)))) If (Length of string) Equal to 4 then do Set (string variable) = (((Substring(string, 1, 1)) + ,) + (Substring(string, 2, 4))) else do nothing If (Length of string) Equal to 5 then do Set (string variable) = (((Substring(string, 1, 2)) + ,) + (Substring(string, 3, 5))) else do nothing etc. etc. Game - Display to (Triggering player), at offset (0.00, 0.00) the text: (This warrior has an experience level of: + (string variable) I'm sure there are more efficient ways, but this should work well enough for now. |
| 10-18-2004, 06:49 AM | #3 |
Guest | hmm... Code:
function InsertCommas takes integer i returns string
local string formatted = "" // or are you supposed to set them to `null' ??
local string unformatted = I2S( i )
// you could probably do sth fancy with modulos, too.
loop
exitwhen unformatted == ""
set formatted = SubString( I2S( i ), StringLength(unformatted) - 4, StringLength(unformatted) ) + "," + formatted // gets the last three characters and adds them to the beginning of <formatted>
set unformatted = SubString(unformatted, 0, StringLength(unformatted) - 4) // what happens if the second value is less than 1? o.0 may need error checking here.
endloop
return formatted
endfunctionI think that's all there is to it. But someone please check this code... >.> (/me has a terrible record with bugs in her code.) Oh, yeah, and I don't know how negative signs work with I2S. So may be buggy about that >.> |
| 10-22-2004, 08:34 PM | #4 |
Can anyone confirm this? I can't seem to get it to work. |
| 10-23-2004, 02:08 AM | #5 |
Well, maybe someone can explain to me how to edit strings like that. Btw, I have no idea what I2S is, so I couldn't help ya there. |
| 10-23-2004, 02:10 AM | #6 |
Integer to string (I to S, I2S). That's JASS for ya. |
| 10-24-2004, 03:28 AM | #7 |
Guest | mhmm... to get it to work, assuming it doesn't have any bugs o.0, you would insert this line of custom text: custom text: set udg_stringVariable = InsertCommas(udg_integerVariableThatYouWantToFormat) If you want it to take a string argument instead of an integer argument, you'll have to change it around a bit >.> |
