A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

Overview

a-calc

A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

(一个字符串四则运算的库, 可以解决js数字计算精度 科学记数法和格式化的问题, 支持千分位小数点格式化输出等操作)

支持的运算符: + - * / %

Install(安装)

npm install a-calc

Import(引入)

commonjs

const {calc, fmt} = require("a-calc")

es module

import a_calc from "a-calc"

const {calc, fmt} = a_calc

browser

">
<script src="node_modules/numbro/dist/numbro.js">script>
<script src="node_modules/a-calc/dist/calc.js">script>
<script>
const {calc, fmt} = a_calc
script>

Calculate(计算)

calc("0.1 + 0.2") // 0.3
calc`0.1 + 0.2` // 0.3
// 以上方式等价

calc("0.1 + 0.2 * 0.3 / 0.4 * (0.5 + 0.6)") // 0.265

Calculate & Format (计算并格式化)

= 5") // 0.30000 calc("0.0000001+ 0.0000001 | >= 5") // 0.0000002 // 千分位 calc("10000000 + 100000000 | ,") // 110,000,000 // 同时指定小数位和千分位 calc("10000000 + 100000000 | =10 ,") // 110,000,000.0000000000">
// 操作小数位数
calc("0.1 + 0.2 | =2") // 0.30
calc("0.11111 + 0.11111 | <=4") // 0.2222
calc("0.11 + 0.11 | <=4") // 0.22
calc("0.1 + 0.2 | >= 5") // 0.30000
calc("0.0000001+ 0.0000001 | >= 5") // 0.0000002

// 千分位
calc("10000000 + 100000000 | ,") // 110,000,000

// 同时指定小数位和千分位
calc("10000000 + 100000000 | =10 ,") // 110,000,000.0000000000

Only Format(只格式化)

calc("0.1 | =2") // 0.10
fmt("0.1 | =2") // 0.10
// calc 具备 fmt 的功能, 但是fmt具备更好的语义

fmt("1000000 | ,") // 1,000,000

Attention(注意)

  • Do not wrap parentheses around single numbers (不要对单个数字包裹括号)

Video Tutorial(视频教程)

https://www.bilibili.com/video/BV17R4y1G7DS?from=search&seid=11611588186602414425&spm_id_from=333.337.0.0

You might also like...

Small utilities for big decimal numbers.

dnum dnum (Decimal Numbers) is a library that allows to operate on large numbers represented as a pair composed of a BigInt for the value, and a Numbe

Dec 21, 2022

Simple quick javascript dropdown plugin with search, that able to work with thousands of options

fstdropdown fstdropdown - simple quick javascript dropdown plugin with bootstrap design and search, that able to work with thousands of options. Now w

Nov 12, 2022

AWS Lambda & Serverless - Developer Guide with Hands-on Labs. Develop thousands line of aws lambda functions interact to aws serverless services with real-world hands-on labs

AWS Lambda & Serverless - Developer Guide with Hands-on Labs. Develop thousands line of aws lambda functions interact to aws serverless services with real-world hands-on labs

AWS Lambda & Serverless - Developer Guide with Hands-on Labs UDEMY COURSE WITH DISCOUNTED - Step by Step Development of this Repository - https://www

Dec 17, 2022

Convert some JavaScript/TypeScript code string into a .d.ts TypeScript Declaration code string

convert-to-dts Converts the source code for any .js or .ts file into the equivalent .d.ts code TypeScript would generate. Usage import { convertToDecl

Mar 3, 2022

Tiny JavaScript library (1kB) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value.

Zero dependency tiny JavaScript library (1kB bytes) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value.

Nov 8, 2022

Digital Identifier is a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential identity-based documents to create a unique digital identity of a person.

Digital Identifier is a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential identity-based documents to create a unique digital identity of a person.

Digital Identifier 🧐 To design and develop a secure, decentralized, anonymous and tampered proof way of maintaining and verifying all essential ident

Dec 17, 2022

A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

Oct 4, 2022

Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mouse is over the marquee, and all with vanilla JavaScript.

TEG Marquee Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mou

Dec 30, 2021

Math magicians is a website for all fans of mathematics. It is a Single Page App (SPA) that allows users to Make simple calculation.

Math Magians Math magicians is a website for all fans of mathematics. It is a Single Page App (SPA) that allows users to Make simple calculation. Live

Sep 6, 2022
Owner
null
A showcase of problems once hard or impossible to solve with CSS alone, now made trivially easy with Flexbox.

Solved by Flexbox A showcase of problems once hard or impossible to solve with CSS alone, now made trivially easy with Flexbox. View Site Viewing the

Philip Walton 13k Jan 2, 2023
Placebo, a beautiful new language agnostic diagnostics printer! It won't solve your problems, but you will feel better about them.

Placebo A beautiful new language agnostic diagnostics printer! ┌─[./README.md] │ > 1 │ What is Placebo? · ───┬──── ·

Robin Malfait 78 Dec 16, 2022
With this File Manager prepared for PHP/Js, you can perform all file operations on your server without any problems.

FileManager With this File Manager prepared for PHP/Js, you can perform all file operations on your server without any problems. Instead of downloadin

Tanzer Demir 4 Sep 23, 2022
A simple react project that contain a single page application (SPA) And a simple caculator to make some calculation and there is a section you can see some Math quotes. Ⓜ💯

A simple react project that contain a single page application (SPA) And a simple caculator to make some calculation and there is a section you can see some Math quotes. Ⓜ??

Reem janina 7 May 31, 2022
Purple hats Desktop is a customisable, automated web accessibility testing tool that allows software development teams to find and fix accessibility problems to improve persons with disabilities (PWDs) access to digital services.

Purple HATS Desktop Purple hats Desktop is a desktop frontend for Purple HATS accessibility site scanner - a customisable, automated web accessibility

Government Digital Services, Singapore 6 May 11, 2023
This package will help parse OData strings (only the Microsoft Dataverse subset). It can be used as a validator, or you can build some javascript library which consumes the output of this library.

@albanian-xrm/dataverse-odata This package will help parse OData strings (only the Microsoft Dataverse subset). It can be used as a validator, or you

AlbanianXrm 3 Oct 22, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023