我有一个字符串,下面有一个方程式如何计算输出
var equation= "((35.8/100)*100)*10%"
我在JS中使用了eval
,但是eval无法支持百分比,任何人都可以帮助找到答案,谢谢
答案 0 :(得分:1)
只需使用正则表达式来获取百分比,将其除以100,然后放回小数即可。
#!/bin/bash
TICKET_NUMBER_REGEX='(ourproject|OURPROJECT)-[0-9]+'
# if CIRCLE_PR_NUMBER is NOT set (meaning it is not a PR
# from a forked repository), then CIRCLE_BRANCH will
# contain the real branch name
if [ -z "${CIRCLE_PR_NUMBER}" ]; then
REAL_BRANCH_NAME="${CIRCLE_BRANCH}"
# if CIRCLE_PR_NUMBER is set, then we need to use it
# to fetch the real branch name
else
REAL_BRANCH_NAME=$(curl -s https://api.github.com/repos/"${CIRCLE_PROJECT_USERNAME}"/"${CIRCLE_PROJECT_REPONAME}"/pulls/"${CIRCLE_PR_NUMBER}"?access_token="${GITHUB_TOKEN}" | jq -r '.head.ref')
fi
TICKET_NUMBER="$(echo "${REAL_BRANCH_NAME}" | grep -Eo "${TICKET_NUMBER_REGEX}")"
# if the ticket number regex does not match, then it's not
# a feature branch, and we shouldn't upload to JIRA.
if [ -z "${TICKET_NUMBER}" ]; then
echo 'Not uploading JIRA APKS for non-feature branch.'
# if it is a feature branch, then use the script to upload the
# build to the correct ticket.
else
./scripts/jiraBuildUpload.py -s -t "$(echo "${REAL_BRANCH_NAME}" | grep -Eo "${TICKET_NUMBER_REGEX}")"
fi