Calculate maximum font size for a fixed number of characters

Hello everyone, I need some advice on how to get the information I describe below, automatically, that is, the app must determine it.
Given the width of the screen, I want to know what font size I need for a label to write x characters (for example 70) using the maximum width of the label, without exceeding the width of the screen.

You could get the width of the Screen and try different mathematics to get the right with every time.

Like:

Font Size: „Screen Width“/12

You can test various numbers for „12“ until it fits every time.

It is a tedious solution but I think it will work.

Thank you, but I don’t like this road, I had already thought and tried it, but it’s not good.
In theory I would need something like screen.widht / x (x = 70) and I have a value with which I calculate the size of the font, but I am missing something …

2 Likes

Thanks @Boban and @Taifun, maybe this is the solution I was looking for. I will try it and inform you.

1 Like

Also check

3 Likes

Thanks, I’ll try it now.

I tried the fontscale, but unfortunately it doesn’t work, it always returns me 1 as a value.
Basically I need to know what maximum font size I can use to insert a number of characters x (eg 70) without exceeding the width of the screen.
Attention I am using a monospace font.