❌ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

Ada: operator with type conversion and rounding

I have a specific problem that I got some issues figuring out. I want to create an operator in Ada that can divide a float value with a character and then return as an integer.

I understand that the operator should be a function with "/" and some kind of type conversion from float value and a character to an integer. But how would the return value look like and which rounding of the float value would be appropriate?

update.

Let's say I would like to put in the float value -21.8 and the character '2'. The answer should be -11. I created a subprogram for this but I feel like the solution could be something more simple.

      function "/"(Float_Val : in Float;
        Ch      : in Character) return integer is
      
   begin
      if Float_Val < Float(0) then return
    (Integer(Float'Rounding(Float_Val)) - (Character'Pos(Ch) - (Character'Pos('0'))) + 1) / (Character'Pos(Ch) - (Character'Pos('0')));
      else return
    (Integer(Float'Rounding(Float_Val)) + (Character'Pos(Ch) - (Character'Pos('0'))) - 1) / (Character'Pos(Ch) - (Character'Pos('0')));
      end if;
   end "/";

and "/" is called in my main program by

 Put(Float_Val / Ch, Width => 0);

Word, templates, rage

This is with Word 2019 for Mac. Why am I using Word, anyway? - because LibreOffice has stopped working with our membership database in SQLite, and wasn’t working at all well with a CSV export. Oh, and Word doesn’t work with SQLite either.

I managed to create a Word template by careful editing of the LibreOffice version; painful to have to work with CSVs, but better than filling in 100 membership letters by hand (most of our members have email, so a Python script using email.mime, smtplib, sqlite3 etc worked for them, leaving the diehards ...)

OK, the organisation has a new chair, time to update the template.

Where is it? Turns out, ~/Library/Group Containers/UBF8T346G9.Office/User Content/Templates. Well done, Microsoft.

And then, the challenge is to find a way of editing the template. Whatever I try, whatever tips I follow on the net, all I can do is edit a document based on the template, which is not what I need to happen!

I would look into PDFs viaΒ fpdf2, but I should only have another year in this post and the next person might have an issue with that. (The same applies to using SQLite, of course. Hmm.)

So I guess it’s back to LibreOffice.


❌
❌