.setText with % rounded to 1 decimal place

23 views
Skip to first unread message

Amanda Kichline

unread,
Sep 27, 2022, 6:41:07 PMSep 27
to Google Apps Script Community
I am working on a script that pushes data from a table in Google Sheets into a table in Google Docs. I've created variables for the data I am pulling from the table in Google Sheets. The data is displayed as a % in the table in Google Sheets (e.g. 70%) but is pushing into the Google Doc as a number (e.g. 0.8). 

I'd like to push the data into the Google Doc as a % rounded to 1 decimal place. See below for code where I'm pulling the variables into the Google Doc table using .setText(variable)

let table2 = body.getTables()[1];
  table2.getRow(0).getCell(1).setText(attendance);
    table2.getRow(1).getCell(1).setText(attendance2);
    table2.getRow(2).getCell(1).setText(attendance3);

Thanks!

Keith Andersen

unread,
Sep 27, 2022, 9:47:31 PMSep 27
to google-apps-sc...@googlegroups.com
Why not create a pivot table, then copy it and paste into the doc...it will as you if you want to link it. Choose yes. Then every time you update the pivot table on the spreadsheet it will update in the document.



Charlie Health
https://www.instagram.com/gocharliehealth/ https://www.facebook.com/gocharliehealth https://www.linkedin.com/company/66938931/admin/ https://twitter.com/charliehealth

CONFIDENTIALITY NOTICE: This email message, including any attachments, is protected under the Federal regulations governing Confidentiality by the Accountability Act of 1996 ("HIPAA"), 45 C.F.R. The Federal rules prohibit any further disclosure of this information unless a written consent is obtained from the person to whom it pertains. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.
Please note: Email is not a secure form of communication and confidentiality cannot be guaranteed. Further, we cannot guarantee that email messages will be read within a given period of time. If you wish to speak with a counselor, call Charlie Health at (406) 361-3001 between 8 a.m. and 5 p.m. Mon.-Fri. Crisis counseling is available by calling 1-800-273-TALK. If your needs are urgent, call 911 or go to the nearest hospital emergency room. 

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/d64b4ddf-c5bb-4785-b02c-a77ce748db8dn%40googlegroups.com.

Andrew Roberts

unread,
Sep 28, 2022, 5:22:31 AMSep 28
to google-apps-sc...@googlegroups.com

Amanda Kichline

unread,
Sep 28, 2022, 9:44:11 AMSep 28
to Google Apps Script Community
Because I'm creating 150+ documents. I'm also auto generating PDFs and emailing them out. So I don't want to do a pivot table 

Laurie J. Nason

unread,
Sep 29, 2022, 12:30:34 AMSep 29
to google-apps-sc...@googlegroups.com
Hi Ananda, 
I would re-iterate what I think someone also suggested earlier - in your google sheet, get the sheet showing what you want to put in the document and when you retrieve the data from it, instead of using getValue(), use getDisplayValue() instead.
Laurie



------ Original Message ------
From "Amanda Kichline" <amanda....@charliehealth.com>
To "Google Apps Script Community" <google-apps-sc...@googlegroups.com>
Date 28/09/2022 16:44:11
Subject Re: [Apps-Script] .setText with % rounded to 1 decimal place

Reply all
Reply to author
Forward
0 new messages