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

问题描述 投票:1回答:1

我正在使用节点JS应用通过ses.sendTemplatedEmail API通过Amazon SES发送电子邮件,>

[如果需要,我也提到了模板的纯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: "[email protected]",
      Template: "mytemplatename",
      Destination: {
        ToAddresses: ["[email protected]"] // 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

编辑

我还需要对数据进行排序,因此不幸地,将其转换为字符串不是可行的选择。

我正在使用ses.sendTemplatedEmail API使用Amazon SES通过Node JS应用发送电子邮件,如果需要如何实现,我还提到了模板的纯html文件以供参考...

html node.js amazon-web-services amazon-ses aws-sdk-nodejs
1个回答
0
投票
您可以在将数字传递给模板之前考虑将其转换为字符串。这样,您就可以控制格式。
© www.soinside.com 2019 - 2024. All rights reserved.