---
title: "X 归档 2020-04-01"
date: "2020-04-01"
tags:
  - x-archive
---

<div class="x-arch-meta">1 条动态 · 图 1 · 视频 0</div>
<div class="x-arch-day">
  <div class="x-arch-item">
    <input type="radio" name="xl-1245298623253970944" id="xl-1245298623253970944-zh" class="x-arch-lang-input x-arch-lang-input-zh" checked aria-label="显示译文" /><input type="radio" name="xl-1245298623253970944" id="xl-1245298623253970944-orig" class="x-arch-lang-input x-arch-lang-input-orig" aria-label="显示原文" /><div class="x-arch-head"><img class="x-arch-avatar" src="https://twimg.tweb.xin/twimg/profile_images/1354154131817168896/tTAiu22d_bigger.jpg" alt="" loading="lazy" referrerpolicy="no-referrer" /><span class="x-arch-kind x-arch-kind-liked" aria-label="赞" title="赞"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z" /></svg></span><a class="x-arch-author" href="https://x.com/Duiker101" target="_blank" rel="nofollow noopener" data-name="Duiker101" data-avatar="https://twimg.tweb.xin/twimg/profile_images/1354154131817168896/tTAiu22d_bigger.jpg">@Duiker101</a><span class="x-arch-time">18:35</span><span class="x-arch-lang-switch" role="group" aria-label="切换原文/译文"><label for="xl-1245298623253970944-zh" class="x-arch-lang-opt x-arch-lang-zh">译</label><label for="xl-1245298623253970944-orig" class="x-arch-lang-opt x-arch-lang-orig">原</label></span><a class="x-arch-link" href="https://x.com/Duiker101/status/1245298623253970944" target="_blank" rel="noopener">原推文<svg class="x-arch-ext" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 7h10v10" /><path d="M7 17 17 7" /></svg></a></div>
    <div class="x-arch-text x-arch-orig">In Javascript, if you need to round down a float, you can use Math.floor, but what if the number can be negative? Doing Math.floor on -2.5 will round down to -3. <br /><br />Maybe, what you really want is Math.trunc, which will always just remove any decimal.<br /><br />#100DaysOfCode #javascript</div>
    <div class="x-arch-text x-arch-trans">在 JavaScript 里，如果你要把浮点数向下取整，可以用 Math.floor，但如果这个数可能是负数呢？对 -2.5 做 Math.floor 会向下舍入成 -3。<br /><br />也许你真正想要的是 Math.trunc，它永远只是直接去掉小数部分。<br /><br />#100DaysOfCode #javascript</div>
    <div class="x-arch-media">
      <a href="/cdn-media/x/2026-10/1245298623253970944-1.png" target="_blank" rel="noopener"><img class="x-arch-img" src="/cdn-media/x/2026-10/1245298623253970944-1.png" alt="@Duiker101 的配图 1/1" loading="lazy" decoding="async" width="562" height="822" /></a>
    </div>
  </div>
</div>
