Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently January 10th, 2025, 5:14 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Adding commas to a number count
PostPosted: September 12th, 2006, 6:26 pm 
Offline

Joined: November 9th, 2004, 7:50 am
Posts: 10
I have a counter that counts upwards every few seconds.

The problem I am having is that I would like to show the number count with commas in situ as the numbers are very large eg 3,245,178

The counter uses a standard text field with a variable that I have.

How can I display the count so that it displays correctly.

Additionally I am using the system clock variables to display the time in the corner and I have noticed that the clock does not display the time correctly for minutes and seconds, it shows the single numbers as 1,2,3 etc intead of 01, 02, 03.

Is it possible to create a mask as in a database application to show the correct formating of the numbers

Attached is the application so far

Any suggestions appreciated


You do not have the required permissions to view the files attached to this post.

_________________
<i>"The aim of argument, or of discussion, should not be victory, but progress.
-- Joseph Joubert"</i>


Top
 Profile  
 
 Post subject:
PostPosted: September 12th, 2006, 9:48 pm 
Offline

Joined: October 26th, 2004, 10:23 am
Posts: 666
Location: Digital Workshop
This function will help:
Code:
function FormatNumber( n )
{
   // Split the number into thousands chunks
   var arrBits = new Array();
   var i = 0;
   while (n > 0)
   {
      arrBits[i] = '' + n % 1000;
      n = Math.floor(n / 1000);

      // Add padding zeroes if necessary
      if (n > 0)
      {
         while (arrBits[i].length < 3)
            arrBits[i] = '0' + arrBits[i];
      }

      i++;
   }
   arrBits = arrBits.reverse();

   // join() uses a comma as the default separator - to use anything
   // else just specify it as a parameter eg. join('.')
   return arrBits.join();
}

Debug.trace( FormatNumber("1") + "\n" );
Debug.trace( FormatNumber("12") + "\n" );
Debug.trace( FormatNumber("123") + "\n" );
Debug.trace( FormatNumber("1234") + "\n" );
Debug.trace( FormatNumber("12345") + "\n" );
Debug.trace( FormatNumber("123456") + "\n" );
Debug.trace( FormatNumber("1234567") + "\n" );
Debug.trace( FormatNumber("12345678") + "\n" );
Debug.trace( FormatNumber("123456789") + "\n" );

With regard to the time
Code:
var Hour = ((SYSTEM_TIME_12HOUR < 10) ? '0' : '') + SYSTEM_TIME_12HOUR;
var Min = ((SYSTEM_TIME_MINUTE < 10) ? '0' : '') + SYSTEM_TIME_MINUTE;
var Sec = ((SYSTEM_TIME_SECOND < 10) ? '0' : '') + SYSTEM_TIME_SECOND;
Debug.trace( Hour + ":" + Min + ":" + Sec );

_________________
ddww Opus Developer


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 83 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group