Multiplying Variables before Writing to File

How can I multiply my variables before they are placed in my CSV file?

I'm trying to manipulate data before it is actually written to the file. I've placed the following code at the beginning of my "writing data to file script".

session.setVariable( "PRICE", "1.5 * COST" );
I completely guessed on this one and I'm not surprised it didn't work.

I'm trying to multiply the variable COST by 1.5 and have PRICE be the result. Both PRICE and COST will be written to the CSV file.

out.write( dataRecord.get( "COST" ) + "\t" );
out.write( dataRecord.get( "PRICE" ) + "\t" );

I would imagine this would be something simple to do but any help is appreciated.

Thanks

Thanks, your right it was a string. However it is saying those functions are not available with my Basic Edition of screen-Scraper. What Edition would I need?

stingToFloat is in both

stingToFloat is in both licensed editions. You can parse the string with Java:

cost = Float.parseFloat(dataRecord.get("COST"));

However, since we're scraping, it would be a good idea to add some code in case your value is null or has a non-numeric character in it.

Just so I understand I do

Just so I understand I do need to upgrade to the licensed versions if I want to accomplish this?
Here is my write to file code:

cost = Float.parseFloat(dataRecord.get("COST"));
price = cost * 1.5;
session.setv("PRICE", price);
import java.io.File;

FileWriter out = null;

try
{
    session.log( "Writing Data to file." );

    // Open up the file to be appended to.
    out = new FileWriter( "ItemsforAmazon.txt", true );

   // Write out the data to the file.
   out.write( dataRecord.get( "COST" ) + "\t" );
out.write( dataRecord.get( "PRICE" ) + "\t" );
 
    out.write( "\n" );

   // Close up the file.
   out.close();
}
catch( Exception e )
{
   session.log( "An error occurred while writing the data to a file: " + e.getMessage() );
}
// End of class loadNotpad

I am extracting my string variable "COST" fine. For example 650.00 is being extracted however I am still getting null for the "PRICE" variable.

Thanks for your help/patience.

See that you're setting PRICE

See that you're setting PRICE as a session variable, and trying to write from a dataReocrd? I'd do this:

// Set name of file to write to.
outputFile = "ItemsforAmazon.txt";

if (dataRecord.get("COST")!=null)
{
        cost = Float.parseFloat(dataRecord.get("COST"));
        price = cost * 1.5;

        // Error catching
        try
        {
                File file = new File(outputFile);
               
                // Open up the file to be appended to.
                out = new FileWriter(outputFile, true );

                // Write out the data to the file.
                out.write(cost + "\t" );
                out.write(price + "\t" );

                out.write("\n");

                // Close up the file.
                out.close();
        }

        catch(Exception e)
        {
                session.log( "An error occurred while writing the data to a file: " + e.getMessage() );
        }
}

You're a saint. thanks

You're a saint. thanks

First you need to make sure

First you need to make sure that COST is a number and not a string. If you scraped it, it's a string. I would do something like:

cost = sutil.stringToFloat(dataRecord.get("COST"));
price = cost * 1.5;
session.setv("PRICE", price);