# \[SOLVED\] String::format silently fails (maybe 2.5.0 M3 issue)

**URL:** <https://community.openhab.org/t/solved-string-format-silently-fails-maybe-2-5-0-m3-issue/81948>\
**Category:** Scripts & Rules\
**Tags:** strings, formatting, milestone\
**Created:** [September 15, 2019, 9:10am UTC](https://community.openhab.org/t/solved-string-format-silently-fails-maybe-2-5-0-m3-issue/81948 "2019-09-15T09:10:52Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![miba](https://community.openhab.org/user_avatar/community.openhab.org/miba/32/33506_2.png) [@miba](https://community.openhab.org/u/miba)\
**Post date:** [September 16, 2019, 4:52am UTC](https://community.openhab.org/t/solved-string-format-silently-fails-maybe-2-5-0-m3-issue/81948/21 "2019-09-16T04:52:03Z")

</div>

Thank you, @rossko57, for your investigations!

I found out that applying [this approach](https://community.openhab.org/t/solved-string-formatting-in-a-rule-of-numbers/34332/2) by @psyciknz that you mentioned also solved the issue:

```csv
// (1) not working original:
// val Number taupunkt_delta = Taupunkt_Differenz.state as DecimalType
// (2) this already satisfies String::format expression:
// val Number taupunkt_delta = Taupunkt_Differenz.state as DecimalType + 0
// (3) providing a floatValue works as well:
val Number taupunkt_delta = (Taupunkt_Differenz.state as DecimalType).floatValue
var String test = String::format("%.1f °C", taupunkt_delta) // fails for (1)
logInfo("myrule.rules", "test=" + test)

```

I would prefer (3) because `MyItem.state as DecimalType + 0` looks quite odd in the code.

> [@rossko57](#):
>
> **Need an OH2.5 M3 user to try the following out please.**
> 
> Okay, so a demo rule to show the issue

I have used my `Taupunkt_Differenz` item for your snippet. The log reads similar to yours

```csv
2019-09-16 06:42:37.715 [INFO] [.smarthome.model.script.myrule.rules] - teststateA=class java.lang.Float
2019-09-16 06:42:37.721 [INFO] [.smarthome.model.script.myrule.rules] - teststateB=class org.eclipse.smarthome.core.library.types.DecimalType
2019-09-16 06:42:37.728 [INFO] [.smarthome.model.script.myrule.rules] - A formatted=2,6 °C
2019-09-16 06:42:37.733 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'format state': f != org.eclipse.smarthome.core.library.types.DecimalType

```

Now I am wondering why this error message does occur in your demo rule but not in my own code…

---

_[View the full topic](https://community.openhab.org/t/solved-string-format-silently-fails-maybe-2-5-0-m3-issue/81948)._
