Source language: Translate to:

String question. Inserting Commas at positions.

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

String question. Inserting Commas at positions.

Postby domino » Tue Apr 25, 2006 2:13 am

My pub generates some numbers from a database.

The generated number range is between 1000 and 100 000 000

The larger numbers are difficult for the user to quickly interpret due to the absence of commas separating the millions and thousands.

I'd like to be able to display the final results with commas inserted in the appropriate positions. (There are no decimal places to consider) and the modified results are for display only they will not be required for further computational purposes.

eg 500000 500,000
10320654 10,320,654
119567398 119,567,398


I`ve had some minor success with splitting the strings into groups and inserting the commas as another string... but my brains beginning to hurt with a plethora of variable names.... Is there is smart way to do this..

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Cipolla » Tue Apr 25, 2006 4:47 am

Hello Dave,

i remember there have been a plugin to convert a given number with seperators. I mean it was called "NeoFormatNum" and i think it was from a spanish developer.

Maybe someone else can help. I could not find it in the moment.
Greetings from Germany
Klaus
User avatar
Cipolla
 
Posts: 166
Joined: Fri Apr 01, 2005 1:45 am
Location: Germany

Postby Cipolla » Tue Apr 25, 2006 4:49 am

Damn, a quick forum search, and here it is:

http://www.neosoftware.com/forum/viewtopic.php?t=13486&highlight=format+number

First think (or search), then reply :oops:
Greetings from Germany
Klaus
User avatar
Cipolla
 
Posts: 166
Joined: Fri Apr 01, 2005 1:45 am
Location: Germany

Postby domino » Tue Apr 25, 2006 6:16 am

Thanks Klaus (and David)

I was hoping to avoid a plugin just for this task....

If there is a programmatic way to do this I would prefer it.. If not then I`ll follow the plugin route....

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby HPW » Tue Apr 25, 2006 6:25 am

You should be able to 'StrLen' your number and loop through it and insert your delimiter.
Hans-Peter
User avatar
HPW
 
Posts: 2510
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Postby Gaev » Tue Apr 25, 2006 6:31 am

Dave:

a) Calling code set ...
Code: Select all
SetVar "[TheNumbers]" "[whatever variable with comma-less numbers]"
GoSub "SeparateTheNumbers"
... on return [TheNumbers] will have the desired values

b) The SubRoutine ...
Code: Select all
:SeparateTheNumbers
... for integers upto 999 999 999

SetVar "[SeparatorCharacter]" ","

StrLen "![TheNumbers]" "[SizeOfTheNumbers]"
SetVar "[FirstLen]" "[SizeOfTheNumbers]-2"
SetVar "[SecondLen]" "[SizeOfTheNumbers]-5"

If "[FirstLen]" ">" "1"
   StrIns "[SeparatorCharacter]" "[TheNumbers]" "[FirstLen]" "[TheNumbers]"
EndIf

If "[SecondLen]" ">" "1"
   StrIns "[SeparatorCharacter]" "[TheNumbers]" "[SecondLen]" "[TheNumbers]"
EndIf

Return



c) If you have a lot of such conversions, instead of a GoSub, you might consider ...
Code: Select all
Call "SeparateTheNumbers" "[whatever variable with comma-less numbers]"


d) For your (continental) European clients, you might even consider passing the delimiter (comma or decimal point) as another parameter ...
Code: Select all
Call "SeparateTheNumbers" "[whatever variable with comma-less numbers]" "[SeparatorCharacter]"
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Wrangler » Tue Apr 25, 2006 7:28 am

Here's one Sam Cox provided in another post:

Math "0[textentry1]*1" "0" "[temp]"
SetVar "[sofar]" ""
StrLen "[temp]" "[len]"
While "[len]" ">" "3"
SubStr "[temp]" "[len]-2" "3" "[x]"
SubStr "[temp]" "1" "[len]-3" "[temp]"
SetVar "[sofar]" ",[x][sofar]"
SetVar "[len]" "[len]-3"
EndWhile
SetVar "[display]" "[temp][sofar]"

I haven't tested this.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Postby domino » Tue Apr 25, 2006 10:29 am

Hans...
You should be able to 'StrLen' your number and loop through it and insert your delimiter.


That was the plan.. but I couldn`t make it work....

Gaev..

Thanks.. Your code is a 'runner' and works nicely


Wrangler...

I recall this having been covered before..but couldn`t find the post.. so thanks. I`ll have a play with Sam's code later on.


Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby David de Argentina » Tue Apr 25, 2006 9:10 pm

Hello Dave,

Take a look of this:

http://specialapps.software-zone.com/fi ... Format.cab

this plugin does exactly you need.

cheers,

David de Argentina
User avatar
David de Argentina
 
Posts: 1553
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Postby domino » Wed Apr 26, 2006 3:04 am

Thanks David... I`ve downloaded a copy for future use. But for this particular job I didn`t want to use any additional plugins. Gaev's routine did the trick this time round.

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron