Page 1 of 1

number formatting

Posted: Wed Jan 13, 2010 3:05 am
by Glenn Boyce
I have attached some code below. I am having trouble formatting the data in the fields, having had a number of attempts. What is the correct cods and where does it go?

Code: Select all

repeat with n = 1 to 12
    if fld ("UOM"&n) = "gm" then
      put fld ("QTY"&n)/1000 into tQTY
    else
      put fld ("QTY"&n) into tQTY
      end if
  put fld ("cost"&n) * tQTY into tsubtotal
  
  put tsubtotal into fld ("subtotal"&n)
  add tQTY to tTotalQty
  add fld ("subtotal"&n) to tTotalCost
fld ("subtotal"&n) is a dollar figure. When I put the format #.00 command in the line before it formats the "n" and screws the script!!

thanks

Re: number formatting

Posted: Wed Jan 13, 2010 10:17 am
by Klaus
Hi Glen,

1. do you mean "set the numberformat to x.xx" or the "format" function?
2. Where do you put this?
3. What and how gets screwed?

A little more info would help me to help you :)


Best

Klaus

Re: number formatting

Posted: Thu Jan 14, 2010 4:15 am
by Glenn Boyce
I've included the actual code below:

Code: Select all

repeat with n = 1 to 12
    if fld ("UOM"&n) = "gm" then
      put fld ("QTY"&n)/1000 into tQTY
    else
      put fld ("QTY"&n) into tQTY
      end if
  put fld ("cost"&n) * tQTY into tsubtotal
  --set the numberformat to "#.00"
  put tsubtotal into fld ("subtotal"&n)
  add tQTY to tTotalQty
  add fld ("subtotal"&n) to tTotalCost
end repeat
I used the "set the number format and what happens is that it sets the number format of "n" to #.00 and the script wil not run.

cheers

Glenn

Re: number formatting

Posted: Sun Jan 17, 2010 1:35 pm
by Mark
Dear Glenn,

What does "the script does not run" mean? Do you get an error message? If you get an error message, you should always post it together with your question on this forum.

Does the following script work for you? If not, where does it go wrong? Do you still get an error message?

Code: Select all

repeat with n = 1 to 12
  if fld ("UOM"&n) = "gm" then
    put fld ("QTY"&n)/1000 into tQTY
  else
    put fld ("QTY"&n) into tQTY
  end if
  put fld ("cost"&n) * tQTY into tsubtotal
  set the numberformat to "#.00"
  put tsubtotal*1 into tsubtotal
  set the numberformat to "#"
  put tsubtotal into fld ("subtotal"&n)
  add tQTY to tTotalQty
  add fld ("subtotal"&n) to tTotalCost
end repeat
Best,

Mark

Re: number formatting

Posted: Mon Jan 18, 2010 3:37 am
by Glenn Boyce
Hi Mark

Don't get an error message but the number in fld ("subtotal"&n) is just an integer

cheers

Glenn

Re: number formatting

Posted: Fri Jan 22, 2010 4:02 pm
by dunbarx
I have played with this,too. Setting the numberFormat pretty much locks in the way numbers are treated in Rev. So if you say:

set numberformat to "#.00"
put 1 into y
add 0 to y
answer y

You get "1.00".

This makes your field references wrong, since you wanted field "myField1" but Rev thought it was field "myField1.00"

You can fix this by extracting only the integer portion. In your script, for example:

put tsubtotal into fld ("subtotal"& char 1 to offset(".",n) - 1 of n)

will get rid of that pesky decimal portion of the number

Craig Newman