Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions cypress/component/TableCellNumber.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { setLocale } from '@nextcloud/l10n'

import TableCellNumber from '../../src/shared/components/ncTable/partials/TableCellNumber.vue'

describe('TableCellNumber', () => {
beforeEach(() => {
setLocale('en_US')
})

it('displays decimals with the current locale separator', () => {
setLocale('de_DE')

mountNumberCell(1.234, { numberDecimals: 3 })

cy.get('.number-display').should('contain.text', '1,234')
})

it('keeps the configured amount of decimal places', () => {
mountNumberCell(1.2, { numberDecimals: 2 })

cy.get('.number-display').should('contain.text', '1.20')
})

it('clamps out-of-range decimal counts for Intl.NumberFormat', () => {
mountNumberCell(1.234567, { numberDecimals: 50 })

cy.get('.number-display').should('contain.text', '1.234567')
})
})

function mountNumberCell(value, columnOverrides = {}) {
cy.mount(TableCellNumber, {
props: {
column: {
id: 1,
numberDecimals: 0,
numberMax: null,
numberMin: null,
numberPrefix: '',
numberSuffix: '',
...columnOverrides,
},
rowId: 1,
value,
},
})
}
12 changes: 11 additions & 1 deletion src/shared/components/ncTable/partials/TableCellNumber.vue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to modify NumberForm.vue too?

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</template>

<script>
import { getCanonicalLocale } from '@nextcloud/l10n'
import cellEditMixin from '../mixins/cellEditMixin.js'

export default {
Expand All @@ -42,7 +43,16 @@ export default {
if (this.value === null) {
return null
}
return this.value.toFixed(this.column?.numberDecimals)
// Intl.NumberFormat only accepts 0..20 fraction digits
const raw = Number(this.column?.numberDecimals ?? 0)
const fractionDigits = Number.isFinite(raw)
? Math.min(20, Math.max(0, Math.trunc(raw)))
: 0
return new Intl.NumberFormat(getCanonicalLocale(), {
maximumFractionDigits: fractionDigits,
minimumFractionDigits: fractionDigits,
useGrouping: false,
}).format(this.value)
},

getStep() {
Expand Down