html - 如何删除nodejs/html中的科学计数法并仅以十进制显示?

标签 html node.js amazon-web-services handlebars.js amazon-ses

我正在使用 Node JS 应用程序通过 amazon SES 使用 ses.sendTemplatedEmail API 发送电子邮件

如果需要的话,我还提到了模板的纯html文件供引用

如何实现预期输出?我不知道出了什么问题,也不知道为什么在 JSON 中指定十进制时使用科学

test.js

const aws=require('aws-sdk')
const ses = new aws.SES({ apiVersion: "2020-12-01",region:"us-east-1"});
var a = {
    "Items": [
        {
            "timeSinceInactive": 0.00011574074074074075,
            "id": "myid1",
            "ssid": "myssid",
            "deviceName": "devicename1"
        },
        {
            "timeSinceInactive": 0.00009259259259259259,
            "id": "myid2",
            "ssid": "myssid2",
            "deviceName": "devicename2"
        }
    ]
}
b = JSON.stringify(a)
console.log(b)
async function sesSendEmail(b,ses) {
    var params = {
      Source: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cfaeadac8fa8a2aea6a3e1aca0a2" rel="noreferrer noopener nofollow">[email protected]</a>",
      Template: "mytemplatename",
      Destination: {
        ToAddresses: ["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6aeafac96b1bbb7bfbaf8b5b9bb" rel="noreferrer noopener nofollow">[email protected]</a>"] // Email address/addresses that you want to send your email
      },
      TemplateData: b,
    }
    try {
      await ses.sendTemplatedEmail(params).promise()
    }
    catch (err) {
      console.log(err)
      throw new Error(err)
    }
  };
  function setAwsCredentials() {
    awsCredentials = {
      region: "us-east-1",
      accessKeyId: "",
      secretAccessKey: ""
    };
    aws.config.update(awsCredentials);
    console.log("Set credentials successfully")
  }
setAwsCredentials()
sesSendEmail(b,ses)

template.html

<table border='2' width='1000'>
    <tr>
        <th>timeSinceInactive</th>
        <th>id</th>
        <th>ssid</th>
        <th>deviceName</th>
    </tr>
    <thead>
        <tr>
            {{#each Items.[0]}}
            {{/each}}
        </tr>
    </thead>
    <tbody>
        {{#each Items}}
        <tr>
            {{#each this}}
            <td>
                 {{this}}
            </td>
            {{/each}}
        </tr>
        {{/each}}
    </tbody>
</table>

当前输出:

timeSinceInactive        id      ssid    deviceName
1.1574074074074075E-4   myid1   myssid  devicename1
9.259259259259259E-5    myid2   myssid2 devicename2

所需输出

timeSinceInactive        id      ssid    deviceName
0.00011574074074074075  myid1   myssid  devicename1
0.00009259259259259259  myid2   myssid2 devicename2

编辑

我还需要对数据进行排序,因此不幸的是,将其转换为字符串并不是一个可行的替代方案。

注意

我正在使用 Amazon SES 中的 createTemlate API,它支持 Handlebars 。因此 html 代码默认使用 Handlebars ...这导致了问题,由于某种原因,它以科学记数法表示,我如何使其仅十进制?

最佳答案

您可以考虑在将数字传递到模板之前将其转换为字符串。这样您就可以控制格式。

关于html - 如何删除nodejs/html中的科学计数法并仅以十进制显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60506622/

相关文章:

mysql - 如何在 AWS 上备份 MySQL 数据库?

javascript - 选择单选输入时如何更改按钮颜色,但输入包装在标签之前的 div 中?

php - HTML 搜索栏区分大小写

javascript - CSS 背景重复 : no-repeat; still repeating

node.js - 在 git bash 中创建一个盒子

javascript - Node js require()[env] 未定义

javascript - IBM Watson Conversation - Angular 集成

php - 获取 Amazon SQS 队列中的消息数

html - CSS 文件中图像相对路径的解决方案取决于包含该图像的文件

amazon-web-services - 如何在 AWS 控制台中删除 AWSServiceRoleForSupport?