Is there a way to remove the last useless zeros from this component using bind:value? #14188
Unanswered
frederikhors
asked this question in
Q&A
Replies: 2 comments
-
@frederikhors You can use an object with getters and setters and do the necessary transformation when reading and writing the state. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Your type is number or null. But you are passing a string into number input. If you use number trailing zeroes will be ignored. If you need to input “text-number” to number input and solve this within the component file you may try: <script lang="ts">
type Props = {
value?: number | null;
};
let {
value = $bindable(),
}: Props = $props();
value = parseFloat(value)
</script>
<input type="number" bind:value /> Or update incorrect type using this trick when passing “text-number” to the component? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have this simple component (playground here):
and in App.svelte:
It shows like this:
Is there a way to remove the last useless zeros?
I know I can use
Intl.NumberFormat
orparseFloat()
outsideInputNumber.svelte
but I need to fix it inside it.Beta Was this translation helpful? Give feedback.
All reactions