# Help with displaying a decimal number

**URL:** <https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645>\
**Category:** Flutter Apprentice\
**Created:** [October 25, 2021, 3:50am UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645 "2021-10-25T03:50:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlstep333](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/carlstep333/32/102075_2.png) [@carlstep333](https://forums.kodeco.com/u/carlstep333)\
**Post date:** [October 25, 2021, 3:50am UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/1 "2021-10-25T03:50:00Z")

</div>

Hi, I’m working through the book and trying to apply what I’ve learnt creating the recipe app to my own ‘playground’ app.

I’ve created a basic currency conversion app, the slider adjusts an input amount and the return gives values for a particular currency. I’d like to limit the decimal places to 2.

![Simulator Screen Shot - iPhone 11 - 2021-10-25 at 07.48.32](https://files.chunter.kodeco.com/original/3X/1/5/15c235ad1101b3ba7ba75af42a4989027d3f36b8.png)

How would I adjust this code to limit the decimal places?

```auto
Text('${currencyFx.exRate * _sliderVal}',
                                style: TextStyle(fontSize: 24.0, fontWeight: FontWeight.w300),),

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![funkyboy](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/funkyboy/32/109099_2.png) [@funkyboy](https://forums.kodeco.com/u/funkyboy)\
**Post date:** [October 25, 2021, 7:19am UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/2 "2021-10-25T07:19:51Z")

</div>

I think you can use this method [toStringAsFixed method - num class - dart:core library - Dart API](https://api.dartlang.org/stable/dart-core/num/toStringAsFixed.html)

---

<div class="post-metadata">

**Author:** ![carlstep333](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/carlstep333/32/102075_2.png) [@carlstep333](https://forums.kodeco.com/u/carlstep333)\
**Post date:** [October 25, 2021, 7:58am UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/3 "2021-10-25T07:58:28Z")

</div>

Thanks @funkyboy …

I have tried the toStringAsFixed method, as you can see I get an error

```auto
Text(('${currencyFx.exRate * _sliderVal}').toStringAsFixed(3),

```

It’s likely I’m not implementing it correctly.  
Any pointers on what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![funkyboy](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/funkyboy/32/109099_2.png) [@funkyboy](https://forums.kodeco.com/u/funkyboy)\
**Post date:** [October 25, 2021, 8:16am UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/4 "2021-10-25T08:16:49Z")

</div>

`Text((currencyFx.exRate * _sliderVal).toStringAsFixed(3)),`

That’s untested but _should_ work.

If you want to dive deeper into Dart (the foundation of Flutter) you can check out our Dart Apprentice book here: [https://www.raywenderlich.com/books/dart-apprentice](https://www.raywenderlich.com/books/dart-apprentice)

---

<div class="post-metadata">

**Author:** ![carlstep333](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/carlstep333/32/102075_2.png) [@carlstep333](https://forums.kodeco.com/u/carlstep333)\
**Post date:** [October 25, 2021, 8:19am UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/5 "2021-10-25T08:19:09Z")

</div>

> [@funkyboy](#):
>
> Text((currencyFx.exRate \* \_sliderVal).toStringAsFixed(3)),

Thanks, struggle as it is just following the Flutter Apprentice book. Think I need to get my head into the courses more. I guess I should review the flutter chapters again, I must have missed something.

---

<div class="post-metadata">

**Author:** ![carlstep333](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/carlstep333/32/102075_2.png) [@carlstep333](https://forums.kodeco.com/u/carlstep333)\
**Post date:** [October 25, 2021, 8:32am UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/6 "2021-10-25T08:32:13Z")

</div>

Is it best to do the Dart Apprentice book before Flutter Apprentice, both at the same time or is it ok to go with Flutter Apprentice for now?

I stumbled late to the Flutter Apprentice course, came across it on the Flutter website and jumped right in and started watching all the videos, reading the book online, so I probably have missed something.

Would you say experimenting is not advised at the early stages, should I stick to following the book and just copy and understand the tutorials?

There is so much information out there, it’s hard to know which roadmap to follow.

---

<div class="post-metadata">

**Author:** ![funkyboy](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/funkyboy/32/109099_2.png) [@funkyboy](https://forums.kodeco.com/u/funkyboy)\
**Post date:** [October 25, 2021, 9:05am UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/7 "2021-10-25T09:05:58Z")

</div>

First, maybe this code is a bit easier to understand.

```auto
var value = (currencyFx.exRate * _sliderVal).toStringAsFixed(3)
Text(value)

```

As for the path, that depends on your current knowledge and learning style. If you are already familiar with other languages with a C-like syntax, Dart and Flutter will be easier to grasp.  
But it’s also ok to experiment, ask questions along the way, and learn some of the foundations later.

It also depends on your goal. If you aim at becoming a professional Flutter dev, you’ll need to have a very good grasp of Dart sooner or later, so it probably makes sense to learn it sooner.

---

<div class="post-metadata">

**Author:** ![jefff9511](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jefff9511/32/102075_2.png) [@jefff9511](https://forums.kodeco.com/u/jefff9511)\
**Post date:** [October 25, 2021, 11:21am UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/8 "2021-10-25T11:21:57Z")

</div>

@carlstep333 … The **${…}** turns whatever is within it to a String …

So you’ve turned the computation into a String. Then by saying **.ToString** , you’re telling it to turn the String into a String. That’s why @funkyboy 's code should work and your doesn’t.

Except I think you want it to be **.toStringAsFixed(2)**

---

<div class="post-metadata">

**Author:** ![carlstep333](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/carlstep333/32/102075_2.png) [@carlstep333](https://forums.kodeco.com/u/carlstep333)\
**Post date:** [October 25, 2021, 11:37am UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/9 "2021-10-25T11:37:24Z")

</div>

Thank Jeff, I could figure out that .toStringAsFixed was the method, just couldn’t work out how to amend it into the existing code. the string interpolation $ was tripping me up. @funkyboy was very helpful.

Thanks for your input.

---

<div class="post-metadata">

**Author:** ![spgms](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/spgms/32/111854_2.png) [@spgms](https://forums.kodeco.com/u/spgms)\
**Post date:** [October 25, 2021, 5:14pm UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/10 "2021-10-25T17:14:01Z")

</div>

@carlstep333 regarding the start with Dart or Flutter, as @funkyboy mentioned it all depends on what your coding background is. For me personally, I have been a SQL developer for over 20 years. I do have some iOS development experience. When I was first introduced to Flutter it was a “Flutter path”. I learned Dart along the way.

That being said, I do recommend reading _Dart Apprentice_ so that you have deeper understanding of Dart, but it is not required to learn Flutter.

---

<div class="post-metadata">

**Author:** ![spgms](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/spgms/32/111854_2.png) [@spgms](https://forums.kodeco.com/u/spgms)\
**Post date:** [October 25, 2021, 5:17pm UTC](https://forums.kodeco.com/t/help-with-displaying-a-decimal-number/154645/11 "2021-10-25T17:17:25Z")

</div>

@carlstep333 One more thing regarding this:

> Hi, I’m working through the book and trying to apply what I’ve learnt creating the recipe app to my own ‘playground’ app.
> 
> I’ve created a basic currency conversion app, the slider adjusts an input amount and the return gives values for a particular currency.

I love that you’re creating a different app! This will help you learn how to adapt what we’ve taught you in _Flutter Apprentice_.

I’d love to see your final project if you’re willing to share. I’m part of the team leading the _Flutter Apprentice_ Book Club and we’re interested to see what people have created. If you’re willing, please share here and also tag me on Twitter at `@GeekMeSpeakStef`.
