question

AttilaCser-6790 avatar image
0 Votes"
AttilaCser-6790 asked AttilaCser-6790 commented

Xamarin Ios String Format issue

Hi,

We have encountered an issue in our mobile app displaying a formatted string. This happens only in iPhone. On Android it works perfectly.
The code is like:

         public string FormatHours(double hours)
         {
             int actualHours = (int)hours;
             int actualMinutes = (int)((hours - Math.Truncate(hours)) * 60);
    
             return string.Format(TranslationService.Get("FormatString.Time"), actualHours, actualMinutes);
         }


This is defined in our viewmodel, and we use that property normally via data-binding.
The FormatString.Time value is: hh\h:mm\m

In the Android version the time is correctly formatted like: 4h 16m
But in Ios we show the string format placeholder all the time like: hh\h:mm\m

Any idea what might be the problem?

Tried on different locales, but same issue.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered AttilaCser-6790 commented

Hello,

Welcome to Microsoft Q&A!

I guess the string format is invalid on iOS .

You can simply combine the string manually as below .

public string FormatHours(double hours)
        {
            int actualHours = (int)hours;
            int actualMinutes = (int)((hours - Math.Truncate(hours)) * 60);

            return actualHours + "h " + actualMinutes + "m";

        }


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you, I think you are right the problem is the string format is wrong.

0 Votes 0 ·