Formatting Text File Output

Post here to ask questions about or get help with the scripting module of QCAD 2.1/2.2.

Moderator: andrew

Formatting Text File Output

Postby carlhelquist » Wed Dec 03, 2008 8:35 pm

I am trying to write decimal values to a text file formatted so that there is a specific number of precision after the decimal point. I seem to be overlooking something very basic about how argDec() and Strings work and I am stuck.

Here is what I have tried so far:

function main() {

var pi=Math.PI;
var piString = new String;
var formatted = new String;

var fileout=new File('c:/pi.txt');
fileout.open(File.WriteOnly);

fileout.writeLine('pi = '+pi);

piString = pi.toString();
formatted = piString.argDec(piString,3,'e',2);
fileout.writeLine('piString = '+piString);
fileout.writeLine('formatted = '+formatted);

fileout.close();

}

This is what pi.txt looks like:

pi = 3.141592653589793
piString = 3.141592653589793
formatted = 3.141592653589793

And the message that pops up in the scripting output:

QString::arg: Argument missing: 3.141592653589793, 3.14159

Can anyone help?

Carl Helquist
carlhelquist
Junior Member
 
Posts: 15
Joined: Wed Dec 03, 2008 7:12 pm

Postby michael » Fri Feb 13, 2009 12:31 pm

http://doc.trolltech.com/4.3/porting-qsa.html

String.argDec() This function is not available in Qt Script. Use replace() or concat() instead.
--
Do you CAD? - I do QCad.
QCad Professional Order Online now:
http://www.ribbonsoft.com/qcad_order.html
michael
Site Admin
 
Posts: 115
Joined: Sun Sep 16, 2007 2:14 pm
Location: Switzerland


Return to QCAD 2.1/2.2 Developers

Who is online

Users browsing this forum: No registered users and 0 guests