Breaking down a long math calculation

then this function should already give you the correct APR.