Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2002
    Location
    Washington State
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    placing a comma... (for numbers)

    I am wondering how to place a comma "," in a certain spot in a value. Example: My value is: 10374 How would I say "place a comma before every 3 numbers BUT no comma if there is no numbers after the first 3 numbers" so I get an output of: 10,374 or something like 103,566,103? I am reading my value from a textfile. Any comments or suggestions would be appreciated.
    ~ Isaac Lloyd ~
    Website Design & Development
    http://www.IsaacLloyd.com

  • #2
    New Coder
    Join Date
    Sep 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try formatNumber(var, 1)
    work together - make world a better place
    Outsource to India
    Web Design India
    Affordable Web hosting

  • #3
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lisbon, CT
    Posts
    339
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    FormatNumber Function
    ---------------------------------------------------------------------------
    FormatNumber(Expression [,Decmals [,LeadDigits[,ParensForNeg [,GroupDigits]]]])
    The FormatNumber function syntax has these parts:
    
    Expression: Required. Expression to be formatted. 
    
    Decimals: Optional. Numeric value indicating how many places to the right of the decimal are displayed. Default value is -1, which indicates that the computer's regional settings are used. 
    
    LeadingDigits: Optional. Tristate constant that indicates whether or not a leading zero is displayed for fractional values. See Settings section for values. 
    
    ParensForNeg: Optional. Tristate constant that indicates whether or not to place negative values within parentheses. See Settings section for values.  
    
    GroupDigits: Optional. Tristate constant that indicates whether or not numbers are grouped using the group delimiter specified in the control panel. See Settings section for values.  
    
    Settings:
    TristateTrue -1 True 
    TristateFalse  0 False 
    TristateUseDefault -2 Use the setting from the computer's regional settings.
    Here is the entire FormatNumber explanation.

    What you want is FormatNumber(yourVar,,,,-1)

    BaldEagle

  • #4
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,

    I had this problem too, and was able to solve it in the meanwhile, but I have an additional question: if the output has a negative value, it's possible to put brackets around it, but is it also to format the output in a different color ?

    I've found somewehere to use the following code, but it doesn't seem to work:

    <%
    If rs.Fields("FIELDNAME") < 0 Then SetTextColor(RGB(201,4,2)) Else
    SetTextColor(RGB(0,0,0))
    End if
    %>

    This is the code to show the values from the database:
    <%=Round(Server.HTMLEncode(rs.Fields("FIELDNAME").Value),2)%>

    I tried to add the lines of code with If else just before the code to show the values, but it doesn't work for me. Does anyone know how to get this working ? I'm quite sure it's quite simple, but I'm more into PHP than ASP...

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •