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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert a number into word document as decimal shows as integer 1

Status
Not open for further replies.

mdav2

Programmer
Aug 22, 2000
363
GB
I have a calculated value that I need to display with two decimal places in a word document. I tried using the round command on the local variable and that makes no difference. It shows the variable as having 2 decimal places but these disappear when inserted into word. Set Decimals To 2 makes no difference either.

Code:
oWord.SELECTION.TEXT = ROUND(lninvtotal,2)

Word has the format command in VBA (see example below from word VBA help)

Code:
MyStr = Format(5459.4, "##,##0.00")    ' Returns "5,459.40".

However, I am not sure how, if at all, I can run this function from VFP. The only way I can think of getting around this would be trying to detect if the result is an integer; turning the value into a string and tacking on ".00".

Any ideas on this would be appreciated. I am running VFP9.

Many thanks

Mark Davies
Warwickshire County Council
 
Mark,

Is there any reason why you have to insert a number? Can you not insert a string instead? In other words:

Code:
oWord.SELECTION.TEXT = TRANSFORM(lnInvTotal, "9999.99")

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike answered moments before I could post a similar reply. Sending numeric values between languages is sometimes problematic due to the different ways the applications handle numbers, so sometimes it is best to default to sending the data in character string format.
 
Yep that worked a treat. Many thanks....

Mark Davies
Warwickshire County Council
 
Just want to add that setting Selection.Text is not the best way to put content into work. Using Range.InsertAfter is a better choice.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top