Mirage Source

Free ORPG making software.
It is currently Tue Sep 28, 2021 2:38 pm

All times are UTC




Post new topic Reply to topic  [ 18 posts ] 
Author Message
 Post subject: 1000 Seperator
PostPosted: Wed Sep 23, 2009 10:14 pm 
Offline
Pro

Joined: Sat Jun 03, 2006 8:32 pm
Posts: 415
I have a program calculating large numbers that are hard to read. I want it to add the 1000 seperator or , to change...

1000 to 1,000

how do I go about doing this? I found Dataformat and changed it to Number and also checked Use 1000 seperator but it still does not work.

THanks

_________________
OREH
http://www.flawsin.com/oreh
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Thu Sep 24, 2009 1:04 am 
Offline
Knowledgeable

Joined: Sun Jan 13, 2008 5:59 pm
Posts: 107
do you mean 100 1,000 10,000 only
or like All numbers?(i.e; 1,354 15,645,324)


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Thu Sep 24, 2009 1:09 am 
Offline
Pro

Joined: Sat Jun 03, 2006 8:32 pm
Posts: 415
All numbers

_________________
OREH
http://www.flawsin.com/oreh
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Thu Sep 24, 2009 2:23 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Here's my very own function I just wrote up. Supports numbers in the trillions ;)

Code:
Public Function FormatNumber(ByVal Number As Currency) As String
Dim loopi As Long
Dim TempStr As String

    FormatNumber = CStr(Number)
   
    If Len(FormatNumber) > 3 Then
        TempStr = Left$(FormatNumber, Len(FormatNumber) - ((Len(FormatNumber) \ 3) * 3))
        For loopi = Len(FormatNumber) \ 3 To 1 Step -1
            TempStr = TempStr & "," & Mid$(CStr(Number), Len(CStr(Number)) - ((loopi * 3) - 1), 3)
        Next
        FormatNumber = TempStr
        If Left$(FormatNumber, 1) = "," Then FormatNumber = Right$(FormatNumber, Len(FormatNumber) - 1)
    End If
   
End Function

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Last edited by GIAKEN on Thu Sep 24, 2009 2:33 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Thu Sep 24, 2009 2:33 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Well I see Aaron is viewing this, so I'll post that I made a fix it just in case you used it and didn't know it has been fixed.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Thu Sep 24, 2009 2:35 am 
Offline
Pro

Joined: Sat Jun 03, 2006 8:32 pm
Posts: 415
How would I go about using this? Right now I just have label captions showing the result of the formula (which equal big numbers)

Im guessing I would have to change it so the formulas are stored in variables and then have the caption = the variable or whatever.

But how do I go about using your function along with that?

_________________
OREH
http://www.flawsin.com/oreh
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Thu Sep 24, 2009 2:36 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Wait, what?

All you do is put your result in the FormatNumber function like: Label1.caption = FormatNumber(result)

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Thu Sep 24, 2009 1:06 pm 
Offline
Regular

Joined: Wed Dec 20, 2006 8:31 pm
Posts: 50
Location: Smyrna, Delaware
lawl, I was only reading because I troll the forums. :p

_________________
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Thu Sep 24, 2009 6:22 pm 
Offline
Pro

Joined: Sat Jun 03, 2006 8:32 pm
Posts: 415
Works good. Thanks.

_________________
OREH
http://www.flawsin.com/oreh
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Thu Sep 24, 2009 8:15 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
I love making complicated looking code :D

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Fri Sep 25, 2009 4:11 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
Code:
Private Sub Command1_Click()
Dim l As Long
    l = 123939201
    Debug.Print Format$(l, "###,###,###,###.00")
End Sub


That will produce: 123,939,201.00

Code:
Private Sub Command1_Click()
Dim l As Long
    l = 12
    Debug.Print Format$(l, "$###,###,###,###.00")
End Sub


Will produce: $12.00


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Fri Oct 23, 2009 1:57 am 
Offline
Pro

Joined: Sat Jun 03, 2006 8:32 pm
Posts: 415
Hey whenever you have a decimal place it throws it all off... can you tell me how to fix that.


GIAKEN wrote:
Here's my very own function I just wrote up. Supports numbers in the trillions ;)

Code:
Public Function FormatNumber(ByVal Number As Currency) As String
Dim loopi As Long
Dim TempStr As String

    FormatNumber = CStr(Number)
   
    If Len(FormatNumber) > 3 Then
        TempStr = Left$(FormatNumber, Len(FormatNumber) - ((Len(FormatNumber) \ 3) * 3))
        For loopi = Len(FormatNumber) \ 3 To 1 Step -1
            TempStr = TempStr & "," & Mid$(CStr(Number), Len(CStr(Number)) - ((loopi * 3) - 1), 3)
        Next
        FormatNumber = TempStr
        If Left$(FormatNumber, 1) = "," Then FormatNumber = Right$(FormatNumber, Len(FormatNumber) - 1)
    End If
   
End Function

_________________
OREH
http://www.flawsin.com/oreh
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Fri Oct 23, 2009 1:59 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Jacob wrote:
Code:
Private Sub Command1_Click()
Dim l As Long
    l = 123939201
    Debug.Print Format$(l, "###,###,###,###.00")
End Sub


That will produce: 123,939,201.00

Code:
Private Sub Command1_Click()
Dim l As Long
    l = 12
    Debug.Print Format$(l, "$###,###,###,###.00")
End Sub


Will produce: $12.00

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Fri Oct 23, 2009 5:36 am 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
have it loop the string once looking for decimal points, then have "For loopi = Len(FormatNumber) \ 3" start at that new place instead.

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Fri Oct 23, 2009 5:55 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Jacob's method is better, but eh...

Code:
Public Function FormatNumber(ByVal Number As Currency) As String
Dim LoopI As Long
Dim TempStr() As String

    TempStr = Split(CStr(Number), ".", , vbTextCompare)
    FormatNumber = TempStr(0)
   
    If Len(FormatNumber) > 3 Then
        TempStr(0) = Left$(FormatNumber, Len(FormatNumber) - ((Len(FormatNumber) \ 3) * 3))
        For LoopI = Len(FormatNumber) \ 3 To 1 Step -1
            TempStr(0) = TempStr(0) & "," & Mid$(FormatNumber, Len(FormatNumber) - ((LoopI * 3) - 1), 3)
        Next
        FormatNumber = TempStr(0)
        If Left$(FormatNumber, 1) = "," Then FormatNumber = Right$(FormatNumber, Len(FormatNumber) - 1)
    End If
   
    If UBound(TempStr) > 0 Then FormatNumber = FormatNumber & "." & TempStr(1)
   
End Function

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Fri Oct 23, 2009 6:03 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
The way Jacob posted is 5x faster than my own hand written one :P

So I adapted to it!

Code:
Public Function FormatNumber(ByVal Number As Currency) As String

    If InStr(1, Number, ".", vbTextCompare) Then
        FormatNumber = Format$(Number, "###,###,###,###,###.####")
    Else
        FormatNumber = Format$(Number, "###,###,###,###,###")
    End If
   
End Function

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Fri Oct 23, 2009 5:30 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: Darunada@gmail.com
does that keep working for numbers larger than 15 digits? The max value of a uint64_t is 20 digits.

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
 Post subject: Re: 1000 Seperator
PostPosted: Fri Oct 23, 2009 6:44 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
In VB6 the max is a currency type which is something like 900 trillion.

Not sure if a double is larger, never used it.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 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:  
cron
Powered by phpBB® Forum Software © phpBB Group