close

no-zero-fractions

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-zero-fractions': 'error',
    },
  },
]);

Rule Details

Remove trailing zero fractions and dangling decimal points from numeric literals. For example, 1.0 becomes 1, 1.010 becomes 1.01, and 1. becomes 1. Numeric separators and exponent spelling are preserved outside the removed fraction.

The rule provides an automatic fix. It preserves required parentheses, keyword spacing, and statement boundaries when changing a numeric member receiver.

Examples of incorrect code:

const value = 123_456.000_000;
const scale = 123.00e20;
const text = 1.00.toString();

Examples of correct code:

const value = 123_456;
const scale = 123e20;
const text = (1).toString();

Options

This rule has no options.

Original Documentation