There are two possible standard ways to handle this, depending on whether you just want to verify this connection or whether you want to verify another device.
First note that all MITM-attacks (by name) work in the way that there is an adversary in the middle of the two legitimate clients. This trivially implies that both clients will see different Diffie-Hellman secrets (if DH is used) because the attacker has to re-encrypt between the connections. It also means that if the handshake1 completes without an error, both parties see the attacker's public key as their peer's key.
First let's consider the connection-based method. For this I'll assume that DH is at the core of the handshake. Example applications include ad-hoc pairing with a bluetooth device with a small screen or encrypted voice comms with a small screen. So to verify the connection, verifying that a (stretched) hash of the shared secret is the same suffices, however don't forget to do this in a way such that it doesn't expose the actual secret key. For this to be secure, obviously, it needs to be hard to find $X$ such that $H(X^a)=H(X^b)$, which has expected complexity of about $2^n$ with $n$ being the number of bits that have to agree in a fixed subset of the output of $H$. So if you want this to be reasonably secure, you want to about $n=80$, so for the work-factor-increase $p$ (iteration-count) $p\cdot 2^m\geq2^n$ should hold with $m$ being the amount of bits displayed to the user. So if you display 16 base64 characters to the user, you encode $16 \cdot 6=96$ bits of information and thus an attacker would have to try about $2^{96}$ keys which is infeasible. Note that because you authenticate the DH secret, only the connection is authenticated.
The alternative standard way is to display a hash of your own public key and the received public key (the valid key from the handshake). In this case you authenticate the other device in the sense that if the signing keys don't change across multiple connections all of these connections are authenticated with one comparison. Much of the above analysis applies as well here, with the difference that you need to find a 2nd-preimage with the hash of the legitimate peer's public key, ie find a public key $pk_e$, such that $H(pk_e)=H(pk_b)$. So if you display 16 base64 characters of the hash, an attacker needs to try $2^{96}$ keys which is infeasible. This method is advantageous to your solution in that it allows users to post their public key hashes to social media or similar decentral out-of-band channels.
The method you proposed is a hybrid of the first above one and the second one. The analysis of the first one applies and the benefits of the device-authentication of the second one are inherited, so if it reflects your usage scenario well, it will work.
1: I mean a handshake here that uses long-term signing keys to establish a shared secret in a secure manner if said keys are correct.
Diffie–Hellman key exchange
. As far as I can tell - that assumes there is no Man-In-The-Middle there. If there were - you might think you're sharing a secret with the "receiver" but both you and the receiver are sharing a (different) secret with the MITM. Am I correct? $\endgroup$if they match
means - if the numbers on both computers' screens are the same. The computer can't know that the number on the other computer is the same - for all it knows - it created a hash from its own key || the MITM's key, and the other computer might be showing a hash of its key || the MITM's key. $\endgroup$