Aller au contenu principal

Recherche

Recherche

Script For Division Result Field Handling

Commentaires

10 commentaires

  • Avatar
    Legacy Poster
    Use the FormatNumber() function.

    For example, if my number is [b]1.123456[/b] and the share name is [i]data[/i], and I only want the first 2 decimal points, my line of code would be:

    [code]formatnumber(data,2)[/code]
    And that would return [b]1.12[/b]


    For more information: www.w3schools.com/vbscript/func_formatnumber.asp
    0
  • Avatar
    Legacy Poster
    I'm using a single-line Expression in Bartender 9.4 I tried your suggestion on the formatnumber by adding it to my original script: (Field("items.Field 11")/ 2.2046) (formatnumber("tot_KG",2))

    Now I get the error saying "Type mismatch: formatnumber". The field tot_KG is the share/name I gave the calculated sub-string field. If I take the quotes away from the "tot_KG", I get a script error: Variable is undefined.

    Using my field names and values how should that line read? I have a flavor for what the syntext should be but mosetly just try different combinations until the script errors go away. Do I need to do this with multi-line script or doesn't that matter?
    0
  • Avatar
    Legacy Poster
    It looks like in your example, the correct code may in fact be: [code]formatnumber((Field("items.Field 11")/ 2.2046),2)[/code]

    A single line script should work. Let me know what happens.
    0
  • Avatar
    Legacy Poster
    It worked like a charm. Also used that to get the Lbs to show as 3 decimals. Thank you for bringing the formatnumber code to my attention and how to use it.
    0
  • Avatar
    Legacy Poster
    Thank you all for your help with my issue. One more question though, is there a way to code it so I just print the whole number if all the numbers to the right of the decimal are zeros? I can live with it the way it is but it would make the label cleaner looking if the result of the calc is 20.00 Kg it would just print 20 Kg and not have the .00 on the end.
    0
  • Avatar
    Legacy Poster
    Never mind I found the solution. If I just replace FormatNumber with Round, it handles the trailing decimals. Problem solved.
    0
  • Avatar
    Legacy Poster
    When I try to use FormatNumber or Round they both give me an error that I cannot use parenthesis in a Sub.
    0
  • Avatar
    Michael Toupin (mtoupin
    [quote name='JasonGriffith' timestamp='1344893828' post='3068']
    When I try to use FormatNumber or Round they both give me an error that I cannot use parenthesis in a Sub.
    [/quote]

    Please post the entire string that you're trying to use. Sounds like just a malformed request.
    0
  • Avatar
    Legacy Poster
    I'm not working any special math into it, I just need the this number which has 3 decimals in the database to be rounded to only 2 (and always 2, even when 0.00) on the label itself, but whether I use FormatNumber() or Round() I get the same error on both.

    FormatNumber(Field("Charges.BoxGrossWtKG"),2)

    Error 6900: "The following script error was found: <Line 1: FormatNumber(Field("Charges.BoxGrossWtKG"),2): Cannot use parentheses when calling a Sub>"
    0
  • Avatar
    Legacy Poster
    I changed the field information to just Value instead and it seems to be working now.
    0

Vous devez vous connecter pour laisser un commentaire.