Javascript的數學難題
首先先考大家幾個數學題,如果這幾題的答案你都能順利的回答,那恭喜你!你可以安心地閱讀這篇文章,你一定能看懂!
題目ㄧ. 0.1 + 0.2 = ?
題目二. 1 – 0.9 = ?
題目三. 0.69 x 10 = ?
相信上面三個簡單的十進位數學運算,你的答案應該會跟我一樣吧?
第一題. 0.3
第二題. 0.1
第三題. 6.9
上面應該是無庸置疑的答案,但是如果我們把這三個題目丟給Javascript去運算之後,得到的結果會變成這樣:
第一題. 0.1 + 0.2 = 0.30000000000000004
第二題. 1 – 0.9 = 0.09999999999999998
第三題. 0.69 x 10 = 6.8999999999999995

什麼!?Javascript連這種小學生的算術都會算錯嗎?其實是有原因的,Javascript所有數字都是以64位浮點數形式儲存,也就是所有的數字都會變轉換成二進位。
上面題目中特別有提到這是3個十進位的數學運算,這也就是這個題目的重點,如果今天的題目改成:10 / 3 = 3.3333333333333334 也許你就能比較明白了,也就是說在十進位中要表達 1 / 3 和二進位中表達 1 / 10 一樣困難。
但其實在我們設計網頁的過程中,使用者是沒有二進位觀念的,只在乎運算出來的數值是否符合十進位的結果,這個時候我們可以利用一些技巧來達成正確的結果。
方法1 . 將小數變成整數後再進行運算
第一題. ((0.1 x 10) + (0.2 x 10)) / 10 = 0.3
第二題. ((1 x 10) – (0.9 x 10)) / 10 = 0.1
第三題. ((0.69 x 100) x 10 / 100) = 6.9
雖說以上的方法能夠順利完成任務,但若運算的數值是動態(Dynamic)的,乘數的部分就比較難下,所以我們可以採用第二種方法。
方法2. Math.js(https://mathjs.org/)
透過網站上提供的js,或是透過CDN(https://cdnjs.com/libraries/mathjs)來引入後,透過以下的方法,就可以正確計算出上面三個題目的結果,其中14指的是精準度,通常已經很夠用了。
第一題. math.format(0.1 + 0.2 , 14) = 0.3
第一題. math.format(1 – 0.9 , 14) = 0.1
第一題. math.format(0.69 x 10 , 14) = 6.9
其實Math.js還有很多好用的功能,可以到它官方的網站閱讀一些文章,基本上所有的數學運算應該都可以透過它來玩完成。
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем:сервисные центры по ремонту техники в мск
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
oral cytotec 200mcg – purchase orlistat online cheap order diltiazem 180mg online
Siham Haleem, a private tour guide for 15 years, says that Doha now has many world-class, modern museums — the National Museum of Qatar being a firm personal favorite. And yet he says that visiting Sheikh Faisal’s museum should still be on everybody’s to-do list.
simpleswap
“For those eager to learn about Qatar’s — and the region’s — heritage and beyond, the museum is an ideal destination,” he says. “Personally, I’m captivated by the car collection, the fossils, and especially the Syrian house, painstakingly transported and reassembled piece by piece.”
Stephanie Y. Martinez, a Mexican-American student mobility manager at Texas A&M University in Qatar likes the museum so much she includes it on all of her itineraries for students visiting from the main campus in Texas.
“The guided tours are very detailed, and the collections found at the museum have great variety and so many stories to unfold,” she says. “Truly, the museum has something to pique everyone’s interest. My favorites are the cars and the furniture exhibits showcasing wood and mother-of-pearl details. Definitely one of my favorite museums in Qatar, every time I visit I learn something new.”
Raynor Abreu, from India, also had praise for the unusual and immense collection.
“Each item has its own story, making the visit even more interesting,” he says. “It’s also impressive to know that Sheikh Faisal started collecting these unique pieces when he was very young. Knowing this makes the museum even more special, as it reflects his lifelong passion for history and culture.”
It takes time and dedication to truly examine the many collections within the museum — especially since most of them are simply on display without explanation.
Eclectic it may be, but it’s hard to fault the determination of Sheikh Faisal, who has brought together items that tell the story of Qatar and the Middle East.
Sarah Bayley, from the UK, says she visited the museum recently with her family, including 16 and 19-year-old teenagers, and was won over by its sheer eccentricity.
“Amazing. Loved it. It is a crazy place.”
1win kg 1win kg .
пин ап – пин ап казино зеркало
Remote and rugged
eigenlayer
A more organic way to see this coast is by the multi-day coastal ferry, the long-running Sarfaq Ittuk, of the Arctic Umiaq Line. It’s less corporate than the modern cruise ships and travelers get to meet Inuit commuters. Greenland is pricey. Lettuce in a local community store might cost $10, but this coastal voyage won’t break the bank.
The hot ticket currently for exploring Greenland’s wilder side is to head to the east coast facing Europe. It’s raw and sees far fewer tourists, with a harshly dramatic coastline of fjords where icebergs drift south. There are no roads and the scattered population of just over 3,500 people inhabit a coastline roughly the distance from New York to Denver.
A growing number of small expedition vessels probe this remote coast for its frosted scenery and wildlife. Increasingly popular is the world’s largest fjord system of Scoresby Sound with its sharp-fanged mountains and hanging valleys choked by glaciers. Sailing north is the prosaically named North East Greenland National Park, fabulous for spotting wildlife on the tundra.
Travelers come to see polar bears which, during the northern hemisphere’s summer, move closer to land as the sea-ice melts. There are also musk oxen, great flocks of migrating geese, Arctic foxes and walrus.
Some of these animals are fair game for the local communities. Perhaps Greenland’s most interesting cultural visit is to a village that will take longer to learn how to pronounce than actually walk around — Ittoqqortoormiit. Five hundred miles north of its neighboring settlement, the 345 locals are frozen in for nine months of the year. Ships sail in to meet them during the brief summer melt between June and August.
Locked in by ice, they’ve retained traditional habits.
“My parents hunt nearly all their food,” said Mette Barselajsen, who owns Ittoqqortoormiit’s only guesthouse. “They prefer the old ways, burying it in the ground to ferment and preserve it. Just one muskox can bring 440 pounds of meat.”
Экран для проекторов с черной окантовкой – улучшение контрастности изображения
экраны для проектора proekcionnye-ehkrany0.ru .
пин ап казино официальный сайт: https://pinupkz.life/
‘For the public to enjoy’
keplr wallet
The museum’s history starts in 1998, when Sheikh Faisal Bin Qassim Al Thani opened a building to the public on his farm some 20 kilometers (12 miles) north of Qatari capital Doha.
A distant relative of Qatar’s ruling family, founder and chairman of Al Faisal Holdings (one of Qatar’s biggest conglomerates), and a billionaire whose business acumen had him recognized as one of the most influential Arab businessmen in the world, Sheikh Faisal had already amassed a substantial private collection of historically important regional artifacts, plus a few quirky pieces of interest, allowing visitors an intimate look into Qatari life and history.
In an interview with Qatari channel Alrayyan TV in 2018, Sheikh Faisal said that the museum started as a hobby.
“I used to collect items whenever I got the chance,” he said. “As my business grew, so did my collections, and soon I was able to collect more and more items until I decided to put them in the museum for the public to enjoy.”
His private cabinet of curiosities has since evolved into a 130-acre complex. Through the fort-like entrance gate lies an oryx reserve, an impressive riding school and stables, a duck pond and a mosque built with a quirky leaning minaret. There’s now even a five-star Marriott hotel, two cafes and the Zoufa restaurant serving modern Lebanese cuisine.
Of course, there’s also the super-sized museum, with a recently-opened car collection housing everything from vintage Rolls-Royces to wartime Jeeps and colorful Buicks. Outside you’ll find peacocks roaming the grounds, and signs warning drivers to be aware of horses and ostriches.
Visitors to the FBQ museum are free to explore the grounds and can even enter the stables to pat the horses.
пин ап казино официальный сайт: https://pinupkz.life/
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем:сервисные центры по ремонту техники в мск
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Why there’s a huge collection of vintage cars stored in the middle of the desert
base bridge
Back at the turn of the 21st century, Qatar was a country with few cultural attractions to keep visitors and residents entertained. Yet the Sheikh Faisal Bin Qassim Al Thani Museum — known as the FBQ Museum — was a place that most people visited as an alternative to the then-still rather ramshackle National Museum of Qatar.
You had to make an appointment, and drive out into the desert, getting lost a few times along the way, but then you were welcomed to the lush Al Samriya Farm with a cup of tea and some cake. The highlight was being allowed into a space crammed full with shelves and vitrines holding all sorts of eclectic artifacts from swords to coins — with the odd car and carriage standing in the grounds.
It wasn’t necessarily the kind of museum you’d find elsewhere in the world, but it was definitely a sight that needed seeing.
Today, it has grown and now claims to be one of the world’s largest private museums. It holds over 30,000 items, including a fleet of traditional dhow sailboats, and countless carpets. There’s also an entire house that once stood in Damascus, Syria.
There are archaeological finds dating to the Jurassic age, ancient copies of the Quran, a section that details the importance of pearling within Qatar’s history, and jewelry dating to the 17th century.
There are also items from 2022’s FIFA World Cup in Qatar including replica trophies, balls used in the games, entry passes, football jerseys and even shelves full of slightly creepy dolls and children’s plush animals.
Some of the more disturbing exhibits include various items of Third Reich paraphernalia in the wartime room, and, strangely enough, several showcases of birds’ legs with marking rings on them. Basically, whatever you can think of, you have a very good chance of finding it here.
Rumor even has it that behind a locked door is a room filled with the late Princess Diana’s dresses and other memorabilia, accessible only to a select few visitors. Another door hides a room, no longer open to the public, filled with collectibles of the late Saddam Hussein.
Everyone is talking about Greenland. Here’s what it’s like to visit
cow swap
A few months ago, Greenland was quietly getting on with winter, as the territory slid deeper into the darkness that envelops the world’s northerly reaches at this time of year.
But President Donald Trump’s musings about America taking over this island of 56,000 largely Inuit people, halfway between New York and Moscow, has seen Greenland shaken from its frozen Arctic anonymity.
Denmark, for whom Greenland is an autonomous crown dependency, has protested it’s not for sale. Officials in Greenland, meanwhile, have sought to assert the territory’s right to independence.
The conversation continues to intensify. A contentious March 28 visit to a US military installation by Usha Vance, the second lady, accompanied by her husband, Vice President JD Vance, was the latest in a series of events to focus attention on Trump’s ambitions for Greenland.
The visit was originally planned as a cultural exchange, but was shortened following complaints from Greenland Prime Minister Mute B. Egede.
Had the Vances prolonged their scheduled brief visit, they would’ve discovered a ruggedly pristine wildernesses steeped in rich Indigenous culture.
An inhospitable icecap several miles deep covers 80% of Greenland, forcing the Inuit to dwell along the shorelines in brightly painted communities. Here, they spend brutally cold winters hunting seals on ice under the northern lights in near perpetual darkness. Although these days, they can also rely on community stores.
The problem for travelers over the years has been getting to Greenland via time-consuming indirect flights. That’s changing. Late in 2024, the capital Nuuk opened a long-delayed international airport. From June 2025, United Airlines will be operating a twice-weekly direct service from Newark to Nuuk.
Two further international airports are due to open by 2026 — Qaqortoq in South Greenland and more significantly in Ilulissat, the island’s only real tourism hotspot.
Curiosity rover makes ‘arguably the most exciting organic detection to date on Mars’
bungee exchange
The NASA Curiosity rover has detected the largest organic molecules found to date on Mars, opening a window into the red planet’s past. The newly detected compounds suggest complex organic chemistry may have occurred in the planet’s past — the kind necessary for the origin of life, according to new research.
The organic compounds, which include decane, undecane and dodecane, came to light after the rover analyzed a pulverized 3.7 billion-year-old rock sample using its onboard mini lab called SAM, short for Sample Analysis at Mars.
Scientists believe the long chains of molecules could be fragments of fatty acids, which are organic molecules that are chemical building blocks of life on Earth and help form cell membranes. But such compounds can also be formed without the presence of life, created when water interacts with minerals in hydrothermal vents.
The molecules cannot currently be confirmed as evidence of past life on the red planet, but they add to the growing list of compounds that robotic explorers have discovered on Mars in recent years. A study detailing the findings was published Monday in the journal Proceedings of the National Academy of Sciences.
The detection of the fragile molecules also encourages astrobiologists that if any biosignatures, or past signs of life, ever existed on Mars, they are likely still detectable despite the harsh solar radiation that has bombarded the planet for tens of millions of years.
“Ancient life, if it happened on Mars, it would have released some complex and fragile molecules,” said lead study author Dr. Caroline Freissinet, research scientist at the French National Centre for Scientific Research in the Laboratory for Atmospheres, Observations, and Space in Guyancourt, France. “And because now we know that Mars can preserve these complex and fragile molecules, it means that we could detect ancient life on Mars.”
1вин официальный сайт вход https://www.1win6020.ru .
что делать с бонусным балансом на 1win https://www.1win6020.ru .
pinup 2025 – pinup 2025
раскрутка сайтов раскрутка сайтов .
пин ап – пин ап вход
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем:сервис центры бытовой техники москва
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем:сервис центры бытовой техники москва
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
пин ап – пин ап вход
пин ап вход – пин ап вход
pinup 2025 – пин ап казино зеркало
пин ап – пин ап казино зеркало
сайтов продвижение puzzleweb.ru/recl3/effjektivnoje-prodvizhjenije-sajtov-v-moskvje-kak-dostich-vysokikh-rjezultatov.php .
продвижение сайтов москва продвижение сайтов москва .
пин ап зеркало: https://pinupkz.life/
раскрутка сайта в топ https://puzzleweb.ru/recl3/effjektivnoje-prodvizhjenije-sajtov-v-moskvje-kak-dostich-vysokikh-rjezultatov.php .
пин ап казино официальный сайт – пин ап казино официальный сайт