INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

not displaying decimals if 0

not displaying decimals if 0

(OP)
Hi,

I'm trying to get a report to display numbers without decimals if there are no.
For input I can enter up to 3 decimals, but display is set to format 999.999.999.99 so I think max 2 decimals are displayed.

Most of the time (98%) no decimals are used but they do get displayed on the report.
What I would like is if there is no decimal it should not show them, like:

6,000 >6
6,500> 6,5
6,550>6,55
6,555>6,555

So I think it should count from the last number and max three back if there are any zero's and if it should strip them?
Not sure how to do this in VFP. Maybe somebody can help me?

RE: not displaying decimals if 0

Hi DDewit,
What version of Fox are you using? If this is a VFP question, you should post it in the Microsoft: Visual Foxpro forum.

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."hammer

RE: not displaying decimals if 0

(OP)
Yes I think it is VFP, but not sure. It is an editor within an ERP programm to set the reports. Not sure where I can see if it is VFP and what version.
But based on the fact this is a Microsoft based erp, I think you are correct. Is there a way to move this thread to the microsoft visual fox pro forum?

RE: not displaying decimals if 0

Quote (ddewit)

It is an editor within an ERP programm to set the reports

It sounds like this is a commercial product and/or an application that someone built for your company.

My first suggestion is to contact the Developer to get them to make the change.
Unless you have the Source code you can't just make something change how it operates and/or is displayed in an application.

Also, even if the application itself is written in Foxpro, sometimes Reports are generated outside of it - example: Crystal Reports, etc.

Perhaps you need to find out more detail on what you are working with and we might be able to assist you better.

Good Luck,
JRB-Bldr

RE: not displaying decimals if 0

(OP)
It's an report generator from Mamut business software. I do not have a developer to make the change.


RE: not displaying decimals if 0

Based on your images, yes, this is Visual FoxPro, not an earlier version. Even better, the visible Dynamics tab means you're in VFP 9.

So to get what you want, you'll want your expression to be something like this (I think the field you're looking at is icNumber; if not, substitute the right name):

CODE

ICASE(ROUND(icNumber,0)=icNumber, TRANSFORM(icNumber, '999,999,999'), MOD(icNumber,.1)=0, TRANSFORM(icNumber,'999,999,999.9'), MOD(icNumber,.01)=0, TRANSFORM(icNumber,'999,999,999.99'), TRANSFORM(icNumber,'999,999,999.999')) 

Tamar

RE: not displaying decimals if 0

I realized there's a much easier solution:

CODE

TRIM(TRANSFORM(icNumber),1,'0') 

Tamar

RE: not displaying decimals if 0

(OP)
This i the field: g_oTemp.LineQtyInv

So I made it like this:
ICASE(ROUND(g_oTemp.LineQtyInv,0)=g_oTemp.LineQtyInv, TRANSFORM(g_oTemp.LineQtyInv, '999,999,999'), MOD(g_oTemp.LineQtyInv,.1)=0, TRANSFORM(g_oTemp.LineQtyInv,'999,999,999.9'), MOD(g_oTemp.LineQtyInv,.01)=0, TRANSFORM(g_oTemp.LineQtyInv,'999,999,999.99'),

But it gives error:missing expression..

RE: not displaying decimals if 0

(OP)

Quote (TRIM(TRANSFORM(icNumber),1,'0'))


Hi Tamar it almost works, it gives:

6,000 > 6
6,500 > 6,5

but then:
6,550 > 6,5,
6,555 > 6,5,5

so first two are ok, but with last 2 are not ok, but I hardly use more than 1 decimals to describe amount of goods, sothis covers 98% of the cases..

edit: and also I wouldlike to add " x" after the number so I made: TRIM(TRANSFORM(g_oTemp.LineQtyInv), 1, '0') + " x"
But that gives wrong results:
6 x
6,5x
6,5, x
6,5,5 x

RE: not displaying decimals if 0

Could it be the Quote() function you put around fiddling with the correct result of TRANSFORM()? Or was that just a typo and you intended to use the quoting option of the forum?

Do you have something in Format property in the Fomrat tab of that report control? This should just be set as this:


All the formatting already is done by the expression you set in the General tab.

Bye, Olaf.

RE: not displaying decimals if 0

(OP)
Olaf you are right!

Format was set to Numeric including a format expression. I changed and removed, now it works!
Thanks you and also Tamar!

RE: not displaying decimals if 0

(OP)
Seems like it i not woking perfectly. When filled in 10,000 or 100,000 or 1000,000 it al give 1 on the report..

RE: not displaying decimals if 0

Hi,

You may want to try something like this

CODE -->

ICASE(ROUND(N, 0) = N, TRANSFORM(N, "999,999,999"), ROUND(N, 1)= N, TRANSFORM(N, "999,999,999.9"), ROUND(N, 2) = N, TRANSFORM(N, "999,999,999.99"), TRANSFORM(N, "999,999,999.999")) 

Please do also check your SET DECIMALS - it should be set to the highest number of decimals you want to have displayed

hth

MK

RE: not displaying decimals if 0

(OP)
I found a sollution (thx to Thierry)
IIF(SET("Point")$TRANSFORM(g_oTemp.LineQtyInv), TRIM(TRIM(TRANSFORM(g_oTemp.LineQtyInv),"0"),SET("Point")), TRANSFORM(g_oTemp.LineQtyInv))+ " x"

RE: not displaying decimals if 0

Indeed a good solution not only taking care of numbers whole numbers with trailing zeros, but also about the decimal point itself.

That's a bummer.

In my FAQ184-7862: How to calculate with more precision I have a parsing routine for converting any number to a string representation and some meta dataa about it like the number of decimal places (really used places, no 0):

CODE

Procedure Parse(tcNum, toNum)
      If Vartype(tcNum)="N"
         tcNum = Transform(tcNum)

         Do Case
            Case Left(tcNum,2)=="0."
               tcNum = Substr(tcNum,2)
            Case Left(tcNum,3)=="-0."
               tcNum = "-"+Substr(tcNum,3)
         Endcase
      Endif

      If Empty(tcNum)
         Error "Can't calculate with empty value of type "+Vartype(tcNum)
      Else
         If !Vartype(tcNum)="C"
            Error "Can't calculate with non string value "+Transform(tcNum)
         Endif
      Endif

      AddProperty(toNum,"sign",Iif(Left(tcNum,1)="-","-","+"))
      AddProperty(toNum,"decimals",Len(tcNum)-Evl(At(".",tcNum),Len(tcNum)))
      AddProperty(toNum,"digits",Chrtran(tcNum,Chrtran(tcNum,"0123456789",""),""))

      If !(Alltrim(Ltrim(tcNum,0,"-","+"),0,"0") == Alltrim(Left(toNum.digits,Len(toNum.digits)-toNum.Decimals)+;
        Iif(toNum.Decimals>0,".","")+Right(toNum.digits,toNum.Decimals),0,"0"))
         Error tcNum+" is not a valid string number"
      Endif
   Endproc 

This is also removing leading 0 from numbers in the form 0.* or -0.* (that's numbers between -1 and 1, excluding -1 and 1), it's a matter of taste, if you leave this zero in. The most important part in there is determining number of decimal places used by the mere TRASNFORM() conversion via Len(tcNum)-Evl(At(".",tcNum),Len(tcNum)). If the decimal point is not there, you have no decimal places at all, and if it's the rightmost, it would be AT the rightmost postion = length of the string and decimal places still are none. If you have no decimal places, you're not allowed to right trim that.

Stripped down to only generating a string 1:1 this could be simplified in testing, whether TRANSFORM()s result has a decimal point - SET('POINT') - in it or not and only if so, right trim 0 and the decimal point itself, and that's exactly what your expression does.

I would put it in a function like

CODE

Function ConvertNumberToString(tnNum)
   Local lcNum
   lcNum = Transform(tnNum)

   If Set('POINT') $ lcNum
      lcNum = Trim(Trim(lcNum,'0'),Set('POINT'))
   Endif

   Return lcNum
Endfunc 

A little trickier would be to add in a decimal point, if it's missing, to then trim it away:

CODE

Function ConvertNumberToString(tnNum)
   Local lcNum
   lcNum = Transform(tnNum)

   If NOT Set('POINT') $ lcNum
      lcNum = lcNum+Set('POINT')
   Endif

   Return Trim(Trim(lcNum,'0'),Set('POINT'))
Endfunc 

Put back into a single expression: TRIM(TRIM(TRANSFORM(g_oTemp.LineQtyInv)+IIF(Set('POINT')$TRANSFORM(g_oTemp.LineQtyInv),'',Set('POINT')),'0'),Set('POINT'))

Bye, Olaf.



RE: not displaying decimals if 0

There's another point in my stringmath library handling that easier:

CODE

Protected Procedure Normalise(tcSign,tcNum)
      If "." $ tcNum
         * both leading and trailing zeros are insignificant
         tcNum = Rtrim(Alltrim(tcNum,0,"0"),0,".")
      Else
         * With no decimal point only leading zeros are insignificant, 
         * trailing zeroes are important (magnitude!)
         tcNum = Ltrim(tcNum,0,"0")
      Endif

      Return tcSign+Evl(tcNum,"0")
   Endproc 

Anyway, I have already been there - had bugs with numbers like that - and still didn't recognize the error case of Tamars too simple approach, too. Besides my class doesn't take SET('POINT') into account.

Bye, Olaf.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close