Source language: Translate to:

Format Numbers With Function NB

NeoBook tips, tricks, code samples and more...

Moderator: Neosoft Support

Format Numbers With Function NB

Postby virger » Wed Jul 19, 2017 10:51 am

Save this function like "FmtNum"
Code: Select all
{NeoBook Function}
Version=5,80
Language=NeoBook
Param=[%nn]|Number|Num To Process
Param=[%dc]|Number|Num Of Decimals
Param=[%sep]|Text|Type Separ
Param=[%dp]|Text|Decimal Point
Param=[%ret]|Variable|Return Number
{End}
.. Puede usarse Trunc, Round
math "[%nn]" "[%dc]" "[%nn]"

strparse "[%nn]" "," "[%nm]" "[%c]"
strlen "[%nm1]" "[%ln]"
if "[%ln]" ">" "2"
   Loop "[%ln]-2" "2" "[%c]"
        StrIns "[%sep]" "[%nm1]" "[%c]" "[%nm1]"
        math "[%c]-2" "" "[%c]"
   endloop
endif

setvar "[%ret]" "[%nm1][%dp][%nm2]"
clearvariables "[%nn],[%nm1],[%nm2],[%c],[%ln]"


setvar "[Num]" "1234567890.54321"

Call "FmtNum" "[Num]" "3" "_" "@" "[NewNum]"

Return [NewNum] = 1_234_567_890@543

Enjoy
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 475
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Format Numbers With Function NB

Postby Neosoft Support » Fri Jul 28, 2017 5:45 pm

That's very cool. Thanks Virger!
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5581
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA


Return to NeoBook Knowledgebase

Who is online

Users browsing this forum: No registered users and 1 guest