Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

not displaying decimals if 0

Status
Not open for further replies.

ddewit

Technical User
Jan 15, 2017
18
0
0
NL
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?
 
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]
 
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?
 
ddewit said:
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

 
It's an report generator from Mamut business software. I do not have a developer to make the change.
error-vfp-formula_f3xzzm.jpg

error-message-vfp-formula_b1i2nt.jpg
 
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
 
I realized there's a much easier solution:

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

Tamar
 
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..
 

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
 
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:
reportcontrolprops_tpnyll.png


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

Bye, Olaf.
 
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!
 
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..
 
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
 
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
 
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 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 [tt]Len(tcNum)-Evl(At(".",tcNum),Len(tcNum))[/tt]. 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:[tt] TRIM(TRIM(TRANSFORM(g_oTemp.LineQtyInv)+IIF(Set('POINT')$TRANSFORM(g_oTemp.LineQtyInv),'',Set('POINT')),'0'),Set('POINT'))[/tt]

Bye, Olaf.



 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top