T
T
T-ed2018-02-03 15:36:08
Google Sheets
T-ed, 2018-02-03 15:36:08

Who will help to finish the script for Google Spreadsheets?

There is this script:

function onOpen() {
  SpreadsheetApp.getUi().createMenu("Extra")
    .addItem("Обновить данные", "updatePoints")
    .addToUi();
}

function updatePoints() {
    var sh = SpreadsheetApp.getActiveSheet();
    var datesColumn = sh.getRange( "A1:A" ).getValues();
    var lastRow = datesColumn.filter( String ).length;
    var oldDate = datesColumn[ lastRow - 1 ][ 0 ];
    var oldPoints = parseFloat( sh.getRange( "B" + lastRow ).getValues() );
    //обновляем валютки на сегодня
    sh.getRange( 'e2' ).setValue( '=ROUND(IMPORTXML("http://www.cbr.ru/scripts/XML_daily.asp"; "//ValCurs/Valute[CharCode=""USD""]/Value");2)' );
    //сохраняем текущую дату-время
    var currentDate = Utilities.formatDate( new Date(), "GMT+3", "dd.MM HH:mm" );
    sh.getRange( 'e1' ).setValue( currentDate );
    //забираем текущие цифры
    var currentPoints = parseFloat( sh.getRange( 'e2' ).getValues() );
    if ( currentPoints !== oldPoints ) {
        //сохраняем новые поинты и дату-время обновления
        lastRow++;
        sh.getRange( "B" + lastRow ).setValue( currentPoints );
        sh.getRange( "A" + lastRow ).setValue( currentDate );
        Logger.log( currentPoints + " <> " + oldPoints )
            //MailApp.sendEmail("", "[Alert] ["+currentDate+"] points raised to " + currentPoints, "Old points " + oldPoints
                              //+"\nNew points "+currentPoints+"\n\nUpdated:"+currentDate,{noReply:true});
    } else {
        Logger.log( currentPoints + " = " + oldPoints )
    }
}

As planned, it should pick up and save the exchange rate of a certain currency against the ruble in the Google Spreadsheet, in the example USD. The problem is that the exchange rate is 560.408. I try to round up with ROUND to 56, 04 but nothing comes out, I'm a complete noob in this. Where is the error, please tell me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Kopendakov, 2018-02-03
@T-ed

Hmm, so here it's just rounding up to 56.00 and that's it. To round to two decimal places, you need to write:
sh.getRange( 'e2' ).setValue( '=ROUND(IMPORTXML(" www.cbr.ru/scripts/XML_daily.asp "; "//ValCurs/Valute [CharCode=""USD""]/Value");2)' );
I've been able to round...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question