Source language: Translate to:

Thousand Separator

General questions about NeoBook

Moderator: Neosoft Support

Thousand Separator

Postby stu » Wed Mar 11, 2015 12:31 pm

Hello,

I remember there used to be a plugin able to convert something like:

10000000,22 into 10,000,000.22 or 10.000.000,22

Either way I need to convert several variables (about 60). I've seen David de Argentina's plugin but the one I'm looking for its not that one. Any ideas?

btw, this might look like total trash but right now its doing the trick...

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
If "[X]" ">" "999999"
   
      SearchStr "." "[X]" "[D]" ""
      StrIns "," "[X]" "[D]-3" "[X]"
      SearchStr "," "[X]" "[C]" ""
      StrIns "," "[X]" "[C]-3" "[X]"

Else
   
   If "[X]" ">" "999"
   
      SearchStr "." "[X]" "[D]" ""
      StrIns "," "[X]" "[D]-3" "[X]"
     
   Endif
     
Endif
Parsed in 0.007 seconds, using GeSHi 1.0.8.10
Microsoft Access hater.
User avatar
stu
 
Posts: 318
Joined: Wed Aug 07, 2013 11:37 am

Re: Thousand Separator

Postby Danito » Wed Mar 11, 2015 12:55 pm

Puedes usar una funcion vbs , FormatCurrency o Formatnumber

Code: Select all
{NeoBook Function}
Version=5.80
Language=VBScript
Param=[%1]|Text|Numero a formatear
Param=[%2]|Text|Numero formateado
{End}
Dim num_sep
num_sep = FormatCurrency([%1], 2, -2, -2, -1)
publication.nbSetVar "[%2]", num_sep
User avatar
Danito
 
Posts: 51
Joined: Thu Mar 11, 2010 7:07 pm

Re: Thousand Separator

Postby stu » Fri Aug 14, 2015 9:18 pm

Feel the need to dig for this topic again... In the past I stick to my primitive code to display thousand separator... I'm still looking for a code efficient way of adding thousand separator to int values. And I'm not talking about currency, just any number...
(?) any ideas or custom plugin? Hell, I'll pay for it.
Microsoft Access hater.
User avatar
stu
 
Posts: 318
Joined: Wed Aug 07, 2013 11:37 am

Re: Thousand Separator

Postby Gaev » Sat Aug 15, 2015 7:40 am

stu:
Feel the need to dig for this topic again... In the past I stick to my primitive code to display thousand separator... I'm still looking for a code efficient way of adding thousand separator to int values. And I'm not talking about currency, just any number...
(?) any ideas or custom plugin? Hell, I'll pay for it.

I'm still looking for a code efficient way of adding thousand separator to int values. And I'm not talking about currency, just any number

A bit more complicated if numbers can also be negative .... but for now, assume they are (unsigned) positive (or zero)

So, your numbers could be ...

a) less than 1,000 (length less than 4)
0 ==> 0
7 ==> 7
34 ==> 34
555 ==> 555

b) 1,000 to 9,999 (length of 4)
1234 ==> 1,234

c) 10,000 to 99,999 (length of 5)
56789 ==> 56,789

d) 100,000 to 999,999 (length of 6)
223344 ==> 223,344

e) 1,000,000 to 9,999,999 (length of 7)
1998877 ==> 1,998,877

f) 10,000,000 to 99,999,999 (length of 8 )
41998877 ==> 41,998,877

g) 100,000,000 to 999,999,999 (length of 9)
641998877 ==> 641,998,877

h) 1,000,000,000 to 9,999,999,999 (length of 10)
3641998877 ==> 3,641,998,877

... etc. etc. up to the highest number you wish to support

So, you would take actions depending on the length of the integer number (make sure you are not tripped up by leading zeroes like 00123)

Say, the integer value is in [myInteger] ...
Code: Select all
SetVar [ThousandSeparator]" "!,"
GoSub "InsertThousandSeparator"

... and subroutine would be ...
Code: Select all
:InsertThousandSeparator
StrLen "[myInteger]" "[IntegerSize]"

If "[IntegerSize]" "<" "4"
   Setvar "[myString]" "[myInteger]"
   Return
EndIf

If "[IntegerSize]" "=" "4"
   StrIns "[ThousandSeparator]" "[myInteger]" "2" "[myString]"
   Return
EndIf

If "[IntegerSize]" "=" "5"
   StrIns "[ThousandSeparator]" "[myInteger]" "3" "[myString]"
   Return
EndIf

If "[IntegerSize]" "=" "6"
   StrIns "[ThousandSeparator]" "[myInteger]" "4" "[myString]"
   Return
EndIf

If "[IntegerSize]" "=" "7"
   StrIns "[ThousandSeparator]" "[myInteger]" "5" "[tempString]"
   StrIns "[ThousandSeparator]" "[tempString]" "2" "[myString]"
   Return
EndIf
 
If "[IntegerSize]" "=" "8"
   StrIns "[ThousandSeparator]" "[myInteger]" "6" "[tempString]"
   StrIns "[ThousandSeparator]" "[tempString]" "3" "[myString]"
   Return
EndIf

If "[IntegerSize]" "=" "9"
   StrIns "[ThousandSeparator]" "[myInteger]" "7" "[tempString]"
   StrIns "[ThousandSeparator]" "[tempString]" "4" "[myString]"
   Return
EndIf

If "[IntegerSize]" "=" "10"
   StrIns "[ThousandSeparator]" "[myInteger]" "8" "[tempString]"
   StrIns "[ThousandSeparator]" "[tempString]" "5" "[temptring]"
   StrIns "[ThousandSeparator]" "[tempString]" "2" "[myString]"
   Return
EndIf

SetVar "[myString]" "****"
Return
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Thousand Separator

Postby stu » Mon Aug 17, 2015 5:12 am

So thats as good as it gets huh?, thats fine, I reckon I can turn it into a function, is that right? thats like the best way if I need to convert about 20 figures on a single page.
Microsoft Access hater.
User avatar
stu
 
Posts: 318
Joined: Wed Aug 07, 2013 11:37 am

Re: Thousand Separator

Postby Gaev » Mon Aug 17, 2015 6:42 am

stu:

I reckon I can turn it into a function, is that right?

Yes you can.

Take a look at this (new and improved) subroutine ... that is more generic ... and takes less commands to accomplish goal ...
Code: Select all
:InsertThousandSeparator2
SetVar "[myString]" "![myInteger][SeparatorStr]"
SetVar "[AllDone]" "No"

While "[AllDone]" "=" "No"

   SearchStr "![SeparatorStr]" "[myString]" "[SeparatorPos]" ""
   If "[SeparatorPos]" "<" "5"
      ... all done
      SetVar "[AllDone]" "Yes"
      ExitWhile
   Else
      ... insert separator
      SetVar "[nextSeparatorPos]" "[SeparatorPos]-3"
      StrIns "![SeparatorStr]" "[myString]" "[nextSeparatorPos]" "[myString]"
   EndIf
EndWhile
... remove extraneous [SeapratorStr] at end of [myString]
Strlen "[myString]" "[myStringLen]"
StrDel "[myString]" "[myStringLen]" "1" "[myString]"
Return

... and call it like this ...
Code: Select all
InputBox "Thousand Separator" "Enter Integer" "[myInteger]"
SetVar "[SeparatorStr]" "!,"
GoSub "InsertThousandSeparator2"
AlertBox "myString" "[myInteger] = [myString]"


This subroutine can also be made into a Function ... and called with something like ...
Code: Select all
Call "stuFormat" "[myInteger]" "![SeparatorStr]" "[myString]"
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Thousand Separator

Postby virger » Mon Aug 17, 2015 7:31 pm

Quiza, al hacer la 'insercion' "al reves". Poner el codigo en un Boton.
Gracias por leerme

Perhaps, when the 'insertion' 'upside down'. Put the code on a button.
Thanks for reading me

Code: Select all
strlen "[Num]" "[Ln]"
math "[Ln]-[Dc]+1" ""  "[Ln]"
StrIns "." "[Num]" "[Ln]" "[Num]"
while "[Ln]" ">" "4"
    math "[Ln]-3" "" "[Ln]"
    StrIns "," "[Num]" "[Ln]" "[Num]"
endwhile


GdoSan/Dr.Sanchez--El Jubilado..Abril 2015
GdoSan/Dr.Sanchez--The Retired ..April 2015
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 505
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Thousand Separator

Postby stu » Tue Aug 18, 2015 6:28 am

Thanks for the replies... I'll go for the Function since I need to convert several numbers on several pages.


-------- EDIT

I ended up adding a bit more for decimal numbers, its just parsing the dot and adding it back in after the thousand separator function finishes...

Function:
Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
setvar "[myInteger]" "[%1]"
setvar "[SeparatorStr]" ","

StrParse "[myInteger]" "." "[IntNumber]" "[IntNumberCount]"

if "[IntNumberCount]" ">" "1"
   Setvar "[DecPart]" ".[IntNumber2]"
else
    Setvar "[DecPart]" ""
endif

SetVar "[myString]" "![IntNumber1][SeparatorStr]"
SetVar "[AllDone]" "No"

While "[AllDone]" "=" "No"
      SearchStr "![SeparatorStr]" "[myString]" "[SeparatorPos]" ""
      If "[SeparatorPos]" "<" "5"
         SetVar "[AllDone]" "Yes"
         ExitWhile
      Else
          SetVar "[nextSeparatorPos]" "[SeparatorPos]-3"
          StrIns "![SeparatorStr]" "[myString]" "[nextSeparatorPos]" "[myString]"
      EndIf
EndWhile

Strlen "[myString]" "[myStringLen]"
StrDel "[myString]" "[myStringLen]" "1" "[myString]"

Setvar "[T[N]]" "[myString][DecPart]"
Parsed in 0.009 seconds, using GeSHi 1.0.8.10


Being called something like (six numbers in this page):

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
Setvar "[G]" "CurrentTotals."
Setvar "[A1]" "[[G]Records]"
Setvar "[A2]" "[[G]People]"
Setvar "[A3]" "[[G]Active]"
Setvar "[A4]" "[[G]Inactive]"
Setvar "[A5]" "[[G]Pensioneer]"
Setvar "[A6]" "[[G]NonPensioneer]"

Setvar "[N]" "1"
Loop "1" "6" "[N]"
     Call "ThousandSeparator" "[A[N]]"
endloop
Parsed in 0.014 seconds, using GeSHi 1.0.8.10


Works pretty good...
Microsoft Access hater.
User avatar
stu
 
Posts: 318
Joined: Wed Aug 07, 2013 11:37 am


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 1 guest