0

I am having trouble to convert a string 'u12345678910' to an integer without scientific notation. So basically, it literally needs to be exactly 12345678910.

How I have approached it:
1. slice the 'u' to get the number i want (after slice its still a string) OR use .replace()
2. tried parseInt(), Number(), both give me a number in scientific notation.
3. parseFloat() & then parseInt(), don't know why but read somewhere that this might work, it didn't.

Why do i need this exact number?
Since it is a chartId of an EmbeddedChart & Google Slides API is giving me the error that the ID needs to be of TYPE_INT32.

Hopefully someone has a solution to this, since its the only thing blocking my project at the moment :(

Please find below some sample code of how to reproduce.

*I am working in Google Apps Script, Chart is in Spreadsheet & I am using the Google Slides API library of Spencer Easton

var ss = SpreadsheetApp.getActiveSpreadsheet(),
  allSheets = ss.getSheets();
var chart = allSheets[0].getCharts()[0],
    chartId = chart.getId(); // this returns 'u12345678910'

var chartStringNumber = chartId.slice(1); // returns 12345678910 (string)
var chartIdNumber = Number(chartStringNumber); // Here I want the result to be typeof INT & 12345678910, but i keep getting a number incl scientific notation. I have also tried parseInt().
4
  • The notion is probably just formatting when the number is printed. If you include the parts of your code thats showing the problem, its more likely someone can help you. Commented Feb 26, 2017 at 17:39
  • You don't give any information about the context you are working in. Spreadsheet ? Webapp? Commented Feb 26, 2017 at 17:48
  • Thank you for your comments, ur completely right. I have added sample code to illustrate my issue. I am working with an embedded chart in Spreadsheet. Commented Feb 26, 2017 at 18:25
  • Try the solution in a related SO post by using unary operator '+' or parseInt(number,10) or Number() to convert a string to number if that solve your issue. Commented Feb 27, 2017 at 9:22

1 Answer 1

1

The chartID returned by the built-in SpreadsheetApp service is a string value that can be overridden using setId(), and starts as an arbitrary value - so it's not the id you want.

To use the Slides API you need the 'real' chart ID which is available from the Advanced Spreadsheet Service, or the directly from the Sheets API.

You can use this code to enumerate the sheets and their charts & real ids using the Advanced Service.

var ch = Sheets.Spreadsheets.get(ss.getId(), {
       "fields": "sheets(charts/chartId,properties(sheetId,title))"
});

var sheets = ch.sheets.map (function (d) {
  return {
    id:d.properties.sheetId,
    name:d.properties.title,
    charts:d.charts
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.